A test log written one line at a time came through a copytruncate rotation with 2,298 lines in the archive, 3,700 lines in the live file, and 167,827 null bytes sitting at the front of the live file where the old text used to be. The file reported 438,000 bytes and occupied about 268 KB on disk. Nothing crashed and nothing printed an error. A plain GNU grep for a line known to be in the file answered binary file matches and showed no log line at all. That result came from one directive behaving exactly as its manual describes, paired with a writer that did not open its file the way the directive assumes.
How logrotate decides a file is due
A state file, a clock, and a run that only happens once a day
Logrotate is not a daemon. It runs, reads its config, checks a state file, rotates what is due, and exits. The logrotate(8) manual says it is “normally” run “as a daily cron job (or by logrotate.timer when using systemd(1)),” and that anyone wanting genuine hourly rotation has to change that schedule and run it hourly. An hourly line in a config file does nothing extra if the program only wakes up once a day.
On the Ubuntu 24.04 test container used for this post (logrotate 3.21.0), the packaged timer is plain:
[Timer]
OnCalendar=daily
AccuracySec=1h
Persistent=true
The cron script that ships alongside it, /etc/cron.daily/logrotate, opens by checking for /run/systemd/system and exits if it finds it, so the two never both fire on a systemd machine. The older post on systemd timers vs cron covers why Persistent=true matters on a box that was powered off at the scheduled hour.
The state file is the part people forget. Each log gets a line recording when it was last rotated, and the default path on this build is /var/lib/logrotate/status. The first time logrotate ever sees a log, it has no history, so it writes one. In the test run below, a brand-new state file produced this, with the clock set to 03:10:
Creating new state
Now: 2026-10-25 03:10
Last rotated at 2026-10-25 03:00
log needs rotating
With daily instead of a forced or size-based rule, that first contact simply records “rotated at this hour” and moves nothing. A five-day simulation further down shows the result: day one produced no archive at all.

The directives in a working block
Seven lines that cover most single-application logs
The global file on the test container is short. Stripped of comments, /etc/logrotate.conf reads weekly, su root adm, rotate 4, create, and include /etc/logrotate.d. Everything specific lives in drop-in files under /etc/logrotate.d/, one per package. The rsyslog drop-in handles /var/log/syslog, auth.log, kern.log and three others in one block with rotate 4, weekly, compress, delaycompress, sharedscripts and a postrotate script.
A block for a custom application looks like this:
/var/log/myapp/app.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
create 0640 root adm
}
What each line does, from the manual:
| Directive | What the manual says it does |
|---|---|
daily |
Rotates every day |
size 1M |
Rotates “only if they grow bigger than size bytes” |
maxsize 1M |
Rotates on size “even before the additionally specified time interval” |
minsize 1M |
Rotates on size “but not before the additionally specified time interval” |
rotate 7 |
Keeps that many old copies “before being removed or mailed” |
compress |
Gzips old versions by default |
delaycompress |
Postpones compressing the newest old file to the next cycle |
missingok |
Skips a missing log without an error |
notifempty |
Leaves an empty log alone |
create |
Makes a fresh, empty file under the original name right after rotation |
copytruncate |
Copies the file, then truncates the original in place |
delaycompress exists for programs that keep writing to the old file for a few seconds after the rename. Leaving app.log.1 as plain text for one cycle means nothing gets gzipped out from under a process that has not let go yet.
The simulation below ran that block, minus rotate 7 in favor of rotate 3, against one file for five days in a row, with 5,000 lines appended before each run and the container clock moved with faketime:
after run on Oct 21:
app.log 83890 bytes first: day 21 line 0
after run on Oct 22:
app.log 0 bytes first:
app.log.1 167780 bytes first: day 21 line 0
after run on Oct 23:
app.log 0 bytes first:
app.log.1 83890 bytes first: day 23 line 0
app.log.2.gz 24326 bytes first: day 21 line 0
after run on Oct 24:
app.log 0 bytes first:
app.log.1 83890 bytes first: day 24 line 0
app.log.2.gz 12199 bytes first: day 23 line 0
app.log.3.gz 24326 bytes first: day 21 line 0
after run on Oct 25:
app.log 0 bytes first:
app.log.1 83890 bytes first: day 25 line 0
app.log.2.gz 12199 bytes first: day 24 line 0
app.log.3.gz 12199 bytes first: day 23 line 0
The output records three behaviors. Day one did nothing, because of the new-state behavior. The .1 file is always uncompressed, which is delaycompress at work. And on the fifth run the archive holding days 21 and 22 vanished, because rotate 3 means three old copies and not one more. These test lines compressed hard (83,890 bytes down to 12,199); real logs with less repetition will not shrink that much.
daily and size in the same block
The second line quietly cancels the first
A common instinct is to write “rotate daily, or sooner if it gets big,” and to spell that as daily followed by size 1M. Logrotate 3.21.0 accepts it and prints a note in verbose mode:
note: 'size' overrides previously specified 'daily'
The test put two 1 KB files through four daily runs. One block used daily plus size 1M; the other used daily plus maxsize 1M. Verbose output for the size file on every run:
log does not need rotating (log size is below the 'size' threshold)
After four days the size log had no archives at all, while the maxsize log had b.log.1, .2 and .3. Then both files were grown by 2 MB and logrotate ran again an hour later on the same day. Both rotated. So maxsize gives “daily, or sooner if big,” and size gives “only when big, never on a schedule.” A quiet log under a size rule can sit for months.
The hourly ceiling still applies to all of this. A size threshold is checked when logrotate runs, and on a stock install that is once a day. A log that fills a disk in four hours will fill it before the daily run ever looks at its size, which is how many people end up reading the disk-full troubleshooting post at 2 a.m.

Testing with -d, -v and -f before trusting a config
Debug mode is a dry run that tells the truth about what it would do
The manual describes -d as debug mode, in which “no changes are made to the logs and the logrotate state file is not updated.” It is the first thing to run against any new block:
logrotate -d /etc/logrotate.d/myapp
On the test container, a dry run against a 1.3 MB file under a size 1M, rotate 3 block printed the whole plan, including the renames it would perform:
rotating log /tmp/lr1/logs/app.log, log->rotateCount is 3
...
renaming /tmp/lr1/logs/app.log to /tmp/lr1/logs/app.log.1
creating new /tmp/lr1/logs/app.log mode = 0640 uid = 0 gid = 0
An ls -l afterward showed the original 1,368,890-byte file untouched. Logrotate 3.21.0 also opens debug output with a warning that debug mode only prints, and suggests -v for anyone who wanted the real thing. -v performs the rotation and narrates it. -f forces rotation whether or not anything is due, per the manual, which makes it the right tool for testing postrotate scripts and the wrong tool for a cron line.
For experiments that should not touch the system’s real history, -s points logrotate at a separate state file. Every test in this post used -s /tmp/.../status, which kept the container’s own /var/lib/logrotate/status clean.
copytruncate vs create
Renaming is clean; copying leaves a gap the clock can measure
There are two ways to hand a running program a fresh log. With create, logrotate renames app.log to app.log.1 and makes a new empty app.log. The catch is that a running program holds an open file descriptor, and a rename does not change which file that descriptor points to. The test proved it with a small Python writer that opened the log once and appended 4,000 lines while logrotate ran partway through:
create mode, writer never reopens:
0 c2/app.log
4000 c2/app.log.1
Every line went into the archive. The new file stayed empty because nothing told the writer to reopen. That is why packaged configs pair create with a postrotate script. The rsyslog drop-in calls /usr/lib/rsyslog/rsyslog-rotate, and the nginx documentation says the log files “need to be renamed first. After that USR1 signal should be sent to the master process,” which makes nginx reopen them.
copytruncate exists for programs with no reopen signal at all. The manual’s description includes its own warning: “there is a very small time slice between copying the file and truncating it, so some logging data might be lost.” It also notes that create has no effect when copytruncate is set.
The test ran the same writer three times with 6,000 lines each, a write roughly every half millisecond, opened with O_APPEND:
append run1: rotated=2432 live=3568 total=6000 lost=0
append run2: rotated=2168 live=3832 total=6000 lost=0
append run3: rotated=2347 live=3652 total=5999 lost=1
Run three dropped line 2347 exactly. The archive ends at line 2346 and the live file starts at 2348, so the missing line landed in the window between copy and truncate. One line in 6,000 is small. Over a year of nightly rotations on a busy service it is not zero, and the line that falls in the gap is never chosen for being unimportant.

Where people get burned
Null bytes, a glob that eats its own tail, and a directory logrotate refuses to touch
copytruncate with a writer that does not append. The opening numbers came from the same writer opened without O_APPEND, keeping its own file offset. After the truncate, its next write landed at the old offset, past the end of the now-empty file, and the kernel filled the gap with zeros. Three runs, three results: 167,827, 176,368 and 177,317 null bytes at the head of the live log, an apparent size of 438,000 bytes, and only about 256 to 268 KB actually allocated on disk because the zero region is a sparse hole. A loss count alone would hide it; in run one only two lines went missing. The log is complete and nearly unreadable. Whether a given program opens its log with O_APPEND is a question for its source or its documentation, and it decides whether copytruncate is merely lossy or actively ugly.
A glob that matches the archives. A block written as /var/log/myapp/* matches app.log, and on the next run it also matches app.log.1. Three daily runs on the test container produced this directory:
app.log
app.log.1
app.log.1.1
app.log.2
app.log.3
The fix is *.log instead of *.
A world-writable or group-writable log directory. With a test directory set to mode 777, logrotate refused outright and exited with status 1:
error: skipping "/tmp/lr7/l/app.log" because parent directory has insecure
permissions (It's world writable or writable by group which is not "root")
Set "su" directive in config file to tell logrotate which user/group should
be used for rotation.
An application installed by hand that makes its own log directory with loose permissions runs straight into this, and on a timer-driven install the error lands in the timer’s journal, never in the app’s own output. Tightening the directory with the octal modes covered in the chmod numbers post, or adding su with the right user and group, both clear it. The manual describes su as rotating “under this user and group instead of using default user/group (usually root).”
The case for leaving it alone
Journald already rotates itself, and not everything belongs in a text file
Plenty of modern services never write a file in /var/log at all. Their output goes to the systemd journal, which caps its own disk use through SystemMaxUse=, set by default to 10% of the size of the respective file system with a 4G ceiling, and a logrotate block for those services rotates nothing because the file it names is empty or missing. Adding missingok silences the complaint but not the misunderstanding.
The stronger objection runs the other way. Programs that write their own log files and also rotate them internally, through a built-in size limit or a logging library, will fight an external logrotate block over the same file. Two janitors with two sets of keys to one boiler room is how archives end up named app.log.1.1.gz. Before writing a block, check whether the application already rotates, and pick one owner.
For anything that does write plain files through a long-lived process, the tests point to one order: create plus a real reopen signal first, copytruncate only when no signal exists, and -d before either one goes near a production box. Which service on your machine still has no way to be told to reopen its log?
Sources
- logrotate(8) manual page, man7.org: https://man7.org/linux/man-pages/man8/logrotate.8.html
- nginx, “Controlling nginx”: https://nginx.org/en/docs/control.html
- logrotate project repository: https://github.com/logrotate/logrotate
- journald.conf(5) manual page, man7.org: https://man7.org/linux/man-pages/man5/journald.conf.5.html
- x9m8, Systemd timers vs cron: https://x9m8.com/systemd-timers-vs-cron/
- x9m8, Linux disk full: https://x9m8.com/linux-disk-full-find-large-files/
- x9m8, Chmod numbers explained: https://x9m8.com/chmod-numbers-755-644-explained/
