LOGROTATE(8)
๐ logrotate(8) โ the rotation, compression & mailing-your-logs situation โจ
Welcome to the System Administrator's Manual bestie ๐ซถ โ this is the page for logrotate(8), and like, honestly? It's kind of iconic. Sit down, grab a strawberry drink ๐, and let's get into it.
๐ธ NAME ๐ธ
logrotate โ rotates, compresses, and mails system logs ๐
โจ SYNOPSIS โจ
logrotate [--force] [--debug] [--state file] [--skip-state-lock]
[--wait-for-state-lock] [--verbose] [--log file] [--mail command]
config_file [config_file2 ...]
๐ฆ DESCRIPTION ๐ฆ
okay so picture this: your systems are out here generating large numbers of log files and somebody has to deal with it. That somebody is logrotate, and it's designed to make administration of those systems so much easier. ๐
It handles the automatic rotation, compression, removal, and mailing of log files. And every single log file can get its own treatment โ handled daily, weekly, monthly, or literally whenever it grows too large. main character energy, honestly. ๐
Normally, logrotate is run as a daily cron job. And here's the thing โ it will not modify a log more than once in one day, unless:
- the criterion for that log is based on the log's size, and
logrotateis being run more than once each day, or - you use the
-for--forceoption. ๐ซก
You can hand it any number of config files on the command line. Later config files may override the options given in earlier files, so likeโฆ the order you list them in genuinely matters. Normally you'd use a single config file that includes any other config files it needs โ see below for how to use the include directive to pull that off. And if you give it a directory on the command line, every file in that directory gets used as a config file. ๐
And if you give it no command line arguments at all? It'll print version and copyright information, plus a short usage summary. No logs rotated, just vibes.
โ ๏ธ If any errors occur while rotating logs, logrotate will exit with non-zero status โ although the state file will still be updated. so like, it fails but it does write the receipts. ๐
๐ฅ OPTIONS ๐ฅ
-f,--forceโ tellslogrotateto force the rotation, even if it doesn't think this is necessary. Sometimes this is useful after adding new entries to alogrotateconfig file, or if old log files have been removed by hand โ because then the new files will be created, and logging will continue correctly. ๐ซถ-d,--debugโ turn on debug mode, which means no changes are made to the logs and thelogrotatestate file is not updated. Only debug messages are printed. It's giving "look but don't touch". ๐-s,--statestatefile โ tellslogrotateto use an alternate state file. This is useful iflogrotateis being run as a different user for various sets of log files. To prevent parallel execution,logrotateby default acquires a lock on the state file, and if it cannot be acquired,logrotatewill exit with value3. The default state file is/var/lib/misc/logrotate.status. And if/dev/nullis given as the state file, thenlogrotatewill not try to lock or write the state file. ๐--skip-state-lockโ do not lock the state file โ for example if locking is unsupported or prohibited. โจ--wait-for-state-lockโ wait until the lock on the state file is released by anotherlogrotateprocess.
๐ญ This option may cause logrotate to wait indefinitely. Use with caution. fr fr, be careful with this one.
-v,--verboseโ turns on verbose mode, for example to display messages during rotation. ๐ฃ๏ธ-l,--logfile โ tellslogrotateto log verbose output into the log_file. The verbose output logged to that file is the same as when runninglogrotatewith the-vswitch. The log file is overwritten on everylogrotateexecution. ๐-m,--mailcommand โ tellslogrotatewhich command to use when mailing logs. This command should accept the following arguments:- the subject of the message given with
-s subject - the recipient.
- the subject of the message given with
The command must then read a message on standard input and mail it to the recipient. The default mail command is /bin/mail. ๐ฌ
--usageโ prints a short usage message. ๐ฉท-?,--helpโ prints help message. ๐ซถ--versionโ display version information. โญ
๐ CONFIGURATION FILE ๐
logrotate reads everything about the log files it should be handling from the series of configuration files specified on the command line. Every config file can:
- set global options โ local definitions override global ones, and later definitions override earlier ones ๐ฅ
- specify logfiles to rotate
๐ก Global options do not affect preceding include directives. Just so you know.
A simple configuration file looks like this:
# sample logrotate configuration file
compress
/var/log/messages {
rotate 5
weekly
postrotate
/usr/bin/killall -HUP syslogd
endscript
}
"/var/log/httpd/access.log" /var/log/httpd/error.log {
rotate 5
mail recipient@example.org
size 100k
sharedscripts
postrotate
/usr/bin/killall -HUP httpd
endscript
}
/var/log/news/* {
monthly
rotate 2
olddir /var/log/news/old
missingok
sharedscripts
postrotate
kill -HUP $(cat /var/run/inn.pid)
endscript
nocompress
}
~/log/*.log {}
The first few lines set global options โ in the example, logs are compressed after they are rotated. And note that comments may appear anywhere in the config file as long as the first non-whitespace character on the line is a #. ๐
Values are separated from directives by whitespace and/or an optional =. Numbers must be specified in a format understood by strtoul(3). (yes, that's a real function, look it up bestie)
The next section of the config file defines how to handle the log file /var/log/messages. The log will go through five weekly rotations before being removed. After the log file has been rotated (but before the old version of the log has been compressed), the command /usr/bin/killall -HUP syslogd will be executed. ๐
The next section defines the parameters for both /var/log/httpd/access.log and /var/log/httpd/error.log. Each is rotated whenever it grows over 100 kilobytes in size, and the old logs files are mailed (uncompressed) to recipient@example.org after going through 5 rotations, rather than being removed. The sharedscripts means that the postrotate script will only be run once for this section, not once for each log which is rotated. Note that log file names may be enclosed in quotes (and that quotes are required if the name contains spaces). Normal shell quoting rules apply, with ', ", and \ characters supported. ๐
The next section defines the parameters for all of the files in /var/log/news. Each file is rotated on a monthly basis. ๐
The last section uses tilde expansion to rotate log files in the home directory of the current user. This is only available if your glob library supports tilde expansion โ and GNU glob does support this. โจ
โ ๏ธ Please use wildcards with caution. If you specify*,logrotatewill rotate all files, including previously rotated ones. ๐ญ A way around this is to use theolddirdirective or a more exact wildcard (such as*.log). iykyk.
๐ซถ Please note: by default when usingsystemd(1), the optionProtectSystem=fullis set in thelogrotate.servicefile. This preventslogrotatefrom modifying logs in/etcand/usr. lowkey important.
Here is more information on the directives which may be included in a logrotate configuration file: ๐
๐ CONFIGURATION FILE DIRECTIVES ๐
These directives may be included in a logrotate configuration file:
๐ Rotation
rotatecount โ log files are rotated count times before being removed or mailed to the address specified in amaildirective. If count is0, old versions are removed rather than rotated. If count is-1, old logs are not removed at all โ except they are affected bymaxage.
๐ฌ use with caution, may waste performance and disk space.
Default is 0.
olddirdirectory โ logs are moved into directory for rotation. The directory must be on the same physical device as the log file being rotated, unlesscopy,copytruncateorrenamecopyoption is used. The directory is assumed to be relative to the directory holding the log file unless an absolute path name is specified. When this option is used, all old versions of the log end up in directory. This option may be overridden by thenoolddiroption. ๐noolddirโ logs are rotated in the directory they normally reside in (this overrides theolddiroption). ๐suuser group โ rotate log files set under this user and group instead of using default user/group (usuallyroot). user specifies the user used for rotation and group specifies the group used for rotation (see the section USER AND GROUP for details). If the user/group you specify here does not have sufficient privilege to make files with the ownership you've specified in acreatedirective, it will cause an error. Iflogrotateruns withrootprivileges, it is recommended to use thesudirective to rotate files in directories that are directly or indirectly in control of non-privileged users. ๐
โฐ Frequency
hourlyโ log files are rotated every hour. Note that usuallylogrotateis configured to be run by crondaily(or bylogrotate.timerwhen usingsystemd(1)). You have to change this configuration and runlogrotatehourly to be able to really rotate logs hourly. โณdailyโ log files are rotated every day. โ๏ธweekly[weekday] โ log files are rotated once each weekday, or if the date is advanced by at least 7 days since the last rotation (while ignoring the exact time). The weekday interpretation is following:0means Sunday,1means Monday, ...,6means Saturday; the special value7means each 7 days, irrespectively of weekday. Defaults to0if the weekday argument is omitted. ๐๏ธmonthlyโ log files are rotated the first timelogrotateis run in a month (this is normally on the first day of the month). ๐yearlyโ log files are rotated if the current year is not the same as the last rotation. ๐sizesize โ log files are rotated only if they grow bigger than size bytes. If size is followed byk, the size is assumed to be in kilobytes. IfMis used, the size is in megabytes, and ifGis used, the size is in gigabytes. Sosize 100,size 100k,size 100Mandsize 100Gare all valid. ๐
โ ๏ธ This option is mutually exclusive with the time interval options, and it causes log files to be rotated without regard for the last rotation time, if specified after the time criteria โ the last specified option takes the precedence. pick a lane bestie.
๐ File selection
missingokโ if the log file is missing, go on to the next one without issuing an error message. See alsonomissingok. ๐ซถnomissingokโ if a log file does not exist, issue an error. This is the default. ๐ญignoreduplicatesโ bestie, when the same log file shows up again later, just ignore it. Don't rotate it twice. ๐ifemptyโ rotate the log file even if it's totally empty, which overrides thenotifemptyoption (ifemptyis the default, so this is the vibe you get for free โจ).notifemptyโ nope, do NOT rotate the log if it's empty (this overrides theifemptyoption). Empty file, no rotation, periodt.minage countโ skip logs that are younger than count days old. Like, they're literally babies, leave them alone ๐ผmaxage countโ delete rotated logs that are older than count days. Quick deets: the age is only checked if the logfile is actually going to be rotated. Alsorotate -1does not hinder removal (iconic, honestly). And the files get mailed to the configured address ifmaillastandmailare both configured. ๐ฌminsize sizeโ logs get rotated once they grow bigger than size bytes, but never before the additionally specified time interval (daily,weekly,monthly, oryearly) hits. The relatedsizeoption is similar except it's mutually exclusive with the time interval options, and it causes log files to be rotated without regard for the last rotation time if it's specified after the time criteria (the last specified option takes the precedence). Whenminsizeis used, both the size and timestamp of a log file are considered. โฐ๐maxsize sizeโ logs get rotated once they grow bigger than size bytes, even before the additionally specified time interval (daily,weekly,monthly, oryearly) arrives. The relatedsizeoption is similar except it's mutually exclusive with the time interval options, and it causes log files to be rotated without regard for the last rotation time if specified after the time criteria (the last specified option takes the precedence). Whenmaxsizeis used, both the size and timestamp of a log file are considered. ๐ฅtabooext [+] listโ this changes the current taboo extension list (peep theincludedirective for the info on taboo extensions). If a+comes before the list of extensions, the current taboo extension list is augmented โ otherwise it's fully replaced. At startup, the taboo extension list is this whole chaotic guest list:,v,.bak,.cfsaved,.disabled,.dpkg-bak,.dpkg-del,.dpkg-dist,.dpkg-new,.dpkg-old,.dpkg-tmp,.new,.old,.orig,.rhn-cfg-tmp-*,.rpmnew,.rpmorig,.rpmsave,.swp,.ucf-dist,.ucf-new,.ucf-old,~โ not one of these got an invite to be rotated ๐ซ๐taboopat [+] listโ changes the current taboo glob pattern list (again, see theincludedirective for the info on taboo extensions and patterns). If a+precedes the list of patterns, the current taboo pattern list gets augmented; otherwise it's replaced. At startup, the taboo pattern list is empty. Nothing there. A whole empty group chat. ๐
๐ Files and Folders (the whole filing system era)
create mode owner group,create owner groupโ right after rotation (before thepostrotatescript runs, so like, immediately), the log file is created again with the same name as the log file just rotated.modesets the mode for the log file in octal (same aschmod(2)),ownersets the user who will own the log file, andgroupsets the group the log file will belong to (see the section USER AND GROUP for the deets). Any of the log file attributes can be omitted, and in that case those attributes for the new file just use the same values as the original log file. You can turn this whole thing off with thenocreateoption. ๐ซถnocreateโ no new log files are created (this overrides thecreateoption). Simple as that.createolddir mode [owner [group]],createolddir [owner [group]]โ if the directory specified by theolddirdirective doesn't exist, it gets created.modesets the mode for theolddirdirectory in octal (same aschmod(2)),ownersets the user who will own theolddirdirectory, andgroupsets the group theolddirdirectory will belong to (see the section USER AND GROUP for details). Ifmodeisn't specified,0755is assumed. This option can be disabled with thenocreateolddiroption. ๐ ๏ธnocreateolddirโ theolddirdirectory is not created by logrotate when it doesn't exist. If it's not there, it's not there, and logrotate is not playing architect today.copyโ make a copy of the log file, but don't change the original at all. Zero changes. Untouched. This one's great if you wanna make a snapshot of the current log file, or when some other utility needs to truncate or parse the file. When this option is used, thecreateoption has no effect, since the old log file stays right where it is. Bonus: thecopyoption allows storing rotated log files on different devices using theolddirdirective. ๐ธnocopyโ don't copy the original log file, and leave it in place (this overrides thecopyoption).copytruncateโ truncate the original log file to zero size in place after making a copy, instead of moving the old log file and optionally creating a new one. Use this when some program can't be told to close its logfile and would otherwise keep writing (appending) to the previous log file forever โ awkward ๐ญ. Heads up though: there's a very small time slice between copying the file and truncating it, so some logging data might get lost. Fr fr, might lose a crumb. When this option is used, thecreateoption has no effect, since the old log file stays in place. Thecopytruncateoption allows storing rotated log files on different devices using theolddirdirective. Also,copytruncateimpliesnorenamecopy. โ๏ธnocopytruncateโ don't truncate the original log file in place after creating a copy (this overrides thecopytruncateoption).renamecopyโ the log file gets renamed to a temporary filename in the same directory by adding a.tmpextension to it. After that, thepostrotatescript runs and the log file is copied from the temporary filename to the final filename. In the end, the temporary filename is removed. Therenamecopyoption allows storing rotated log files on different devices using theolddirdirective. Andrenamecopyimpliesnocopytruncate. ๐norenamecopyโ don't rename and copy the original log file (this overrides therenamecopyoption).shredโ delete log files usingshred -uinstead ofunlink(). This should ensure that logs are not readable after their scheduled deletion โ very main character security energy ๐. It's off by default. See alsonoshred.noshredโ don't useshredwhen deleting old log files. See alsoshred.shredcycles countโ asks GNUshred(1)to overwrite log files count times before deletion. Without this option, shred's default gets used. ๐allowhardlinkโ rotate files with multiple hard links; this is off by default. โ ๏ธ Careful bestie: the target file might get emptied, e.g. withshredorcopytruncate. Use with caution, especially when the log files are rotated as root. Like, this is the "don't run with scissors" of directives.noallowhardlinkโ don't rotate files with multiple hard links. See alsoallowhardlink.
๐๏ธ Compression (smaller files, cuter logs)
compressโ old versions of log files are compressed withgzip(1)by default. See alsonocompress. ๐nocompressโ old versions of log files are not compressed. See alsocompress.compresscmdโ specifies which command to use to compress log files. The default isgzip(1). See alsocompress.uncompresscmdโ specifies which command to use to uncompress log files. The default isgunzip(1).compressextโ specifies which extension to use on compressed logfiles, if compression is enabled. The default follows that of the configured compression command.compressoptionsโ command line options may be passed to the compression program, if one is in use. The default, forgzip(1), is"-6"(biased towards high compression at the expense of speed). If you use a different compression command, you may need to change thecompressoptionsto match. ๐๏ธdelaycompressโ postpone compression of the previous log file to the next rotation cycle. This only has effect when used in combination withcompress. It's the move when some program can't be told to close its logfile and thus might keep writing to the previous log file for some time. โณnodelaycompressโ don't postpone compression of the previous log file to the next rotation cycle (this overrides thedelaycompressoption).
๐ท๏ธ Filenames (naming things is literally an art form)
extension extโ log files with the ext extension can keep it after rotation. If compression is used, the compression extension (normally.gz) appears after ext. Example: you have a logfile namedmylog.fooand you want to rotate it tomylog.1.foo.gzinstead ofmylog.foo.1.gz. Slay, keeping the whole name together ๐addextension extโ log files are given the final extension ext after rotation. If the original file already ends with ext, the extension isn't duplicated, but merely moved to the end โ that is, bothfilenameandfilenameextwould get rotated tofilename.1ext. If compression is used, the compression extension (normally.gz) appears after ext. ๐start countโ this is the number to use as the base for rotation. For example, if you specify0, the logs will be created with a.0extension as they're rotated from the original log files. If you specify9, log files will be created with a.9, skipping0โ8. Files will still be rotated the number of times specified with therotatedirective. ๐ขdateextโ archive old versions of log files adding a date extension likeYYYYMMDDinstead of simply adding a number. The extension may be configured using thedateformatanddateyesterdayoptions. Obsessed with a timestamped glow-up ๐ โจnodateextโ do not archive old versions of log files with a date extension (this overrides thedateextoption).dateformatformat_string โ sets the extension fordateextusing strftime(3)-ish notation. Only%Y%m%d%H%M%S%V%sand%zare allowed, bestie, that's the whole guest list ๐ . Default is-%Y%m%d, except for hourly, which rocks-%Y%m%d%Has its default. Lowkey important: the character separating the log name from the extension is part of the dateformat string itself. Also your system clock has to be set past Sep 9th 2001 for%sto work correctly โ no time-traveling, gorl ๐ฐ๏ธ. And the datestamps this format generates must be lexically sortable (year first, then month, then day โ like,2001/12/01is ok, but01/12/2001is not, because01/11/2002would sort lower while it's actually later). Why do we care? Because with the rotate option, logrotate sorts all the rotated filenames to figure out which logfiles are older and should get yeeted ๐๏ธ.dateyesterdayโ uses yesterday's date instead of today's when building thedateextextension, so the rotated log file's name has the same date as the timestamps inside it. Matchy-matchy, we love consistency โจ.datehouragoโ uses the hour ago instead of the current date to build thedateextextension, so the rotated log file has an hour in its name that matches the timestamps within it. Super useful withrotate hourly๐.
๐ Mail
mailaddress โ when a log gets rotated out of existence, it gets mailed to address. If you don't want mail for a particular log, use thenomaildirective instead.nomailโ do not mail old log files to any address. Silence is golden ๐คซ.mailfirstโ when using themailcommand, mail the just-rotated file instead of the about-to-expire one.maillastโ when using themailcommand, mail the about-to-expire file instead of the just-rotated one (this is the default, fyi).
๐ Additional config files
includefile_or_directory โ reads the file you pass as an argument as if it was included inline right where theincludedirective sits. If you hand it a directory, most of the files in that directory get read in alphabetic order before processing of the including file continues ๐. The only files that get ignored are ones that aren't regular files (think directories and named pipes) and files whose names end with one of the taboo extensions or patterns, as specified by thetabooextortaboopatdirectives respectively. The given path may start with~/to make it relative to the home directory of the executing user ๐ . And for security reasons, configuration files must not be group-writable nor world-writable โ no cap, keep those perms locked down ๐.
๐ฌ Scripts
sharedscriptsโ normally,prerotateandpostrotatescripts run for each log that's rotated, and the absolute path to the log file gets passed as the first argument to the script. That means a single script may run multiple times for log file entries that match multiple files (like the/var/log/news/*example). Ifsharedscriptsis specified, the scripts only run once, no matter how many logs match the wildcarded pattern, and the whole pattern is passed to them ๐ซถ. However โ if none of the logs in the pattern need rotating, the scripts won't run at all. And if the scripts exit with error (or any log fails to rotate), the remaining actions won't be executed for any logs. This option overrides thenosharedscriptsoption.nosharedscriptsโ runsprerotateandpostrotatescripts for every log file that's rotated (this is the default, and it overrides thesharedscriptsoption). The absolute path to the log file is passed as the first argument to the script. For thepostrotatescript, the absolute path to the final rotated log file is passed as the second argument. If the scripts exit with error, the remaining actions won't be executed for the affected log only ๐.firstactionscriptendscriptโ the script runs once before all log files matching the wildcarded pattern are rotated, before theprerotatescript runs, and only if at least one log will actually be rotated. These directives may only appear inside a log file definition. The whole pattern is passed to the script as its first argument. If the script exits with an error, no further processing is done ๐. See alsolastactionand the SCRIPTS section.lastactionscriptendscriptโ the script runs once after all log files matching the wildcarded pattern are rotated, after thepostrotatescript runs, and only if at least one log is rotated. These directives may only appear inside a log file definition. The whole pattern is passed to the script as its first argument. If the script exits with an error, just an error message is shown (since this is the last action). See alsofirstactionand the SCRIPTS section.prerotatescriptendscriptโ the script runs before the log file and its old logs are rotated, and only if the log will actually be rotated. These directives may only appear inside a log file definition. Normally, the absolute path to the log file is passed as the first argument to the script. Ifsharedscriptsis specified, the whole pattern is passed to the script. See alsopostrotateand the SCRIPTS section. Seesharedscriptsandnosharedscriptsfor error handling.postrotatescriptendscriptโ the script runs after the log file is rotated and before the log file is being compressed (timing is everything, bestie โฑ๏ธ). These directives may only appear inside a log file definition. Normally, the absolute path to the log file is passed as the first argument to the script and the absolute path to the final rotated log file is passed as the second argument to the script. Ifsharedscriptsis specified, the whole pattern is passed as the first argument to the script, and the second argument is omitted. See alsoprerotateand the SCRIPTS section. Seesharedscriptsandnosharedscriptsfor error handling.preremovescriptendscriptโ the script runs once, just before removal of a log file. logrotate passes the name of the file that's soon to be removed as the first argument to the script. See alsofirstactionand the SCRIPTS section. RIP little log ๐ชฆ.
๐ SCRIPTS
The lines between the starting keyword (e.g. prerotate) and endscript โ both of which must appear on lines by themselves โ are executed (using /bin/sh). The script inherits some traits from the logrotate process, including stderr, stdout, the current directory, the environment, and the umask ๐. Scripts are run as the invoking user and group, irrespective of any su directive. If the --log flag was specified, file descriptor 3 is the log file. The current working directory is unspecified (so like, don't assume, gorl).
๐ค USER AND GROUP
User and group identifiers are resolved first by trying the textual representation and, in case it fails, afterwards by the numeric value. Text first, numbers as the backup plan ๐ .
๐๏ธ FILES
/var/lib/misc/logrotate.statusโ default state file./etc/logrotate.confโ configuration options.
๐ SEE ALSO
chmod(2), gunzip(1), gzip(1), mail(1), shred(1), strftime(3), strtoul(3), <https://github.com/logrotate/logrotate>
๐ AUTHORS
Erik Troan, Preston Brown, Jan Kaluza.
<https://github.com/logrotate/logrotate>
okay that's the whole page, you made it, I'm so proud of you ๐ซถโจ This absolutely iconic piece of documentation is version 3.22.0 of LOGROTATE(8) on Linux โ go forth and rotate responsibly, bestie ๐๐๐ฆ
๐ฆ where this page comes from
- opensuse-leap 16.0: logrotate 3.22.0-160000.2.2 ยท GPL-2.0-or-later
- opensuse-leap 16.0: logrotate 3.22.0-160000.2.2 ยท GPL-2.0-or-later
- opensuse-leap 16.0: logrotate 3.22.0-160000.2.2 ยท GPL-2.0-or-later
- opensuse-leap 16.0: logrotate 3.22.0-160000.2.2 ยท GPL-2.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms