logrotate(8)
Rotates, compresses, and removes old log files based on rules configured in /etc/logrotate.conf and /etc/logrotate.d/.
Synopsis
logrotate [OPTION]... CONFIG_FILEDescription
Logrotate is a system utility that manages the automatic rotation of log files. It prevents log files from consuming excessive disk space by compressing, archiving, and deleting old logs according to specified rules.
Configuration is typically handled through /etc/logrotate.conf for global settings and individual files in /etc/logrotate.d/ for application-specific rotation policies. Logrotate is usually run daily via cron (/etc/cron.daily/logrotate) and can also be executed manually.
When a log file is rotated, it is renamed with a numeric or date suffix, optionally compressed, and new empty log files can be created automatically. Post-rotation scripts can reload services to recognize the new log file.
Common options
| Flag | What it does |
|---|---|
-f, --force | Force rotation of all log files, regardless of rotation conditions |
-v, --verbose | Print informational messages about what is being done |
-d, --debug | Debug mode; do not actually rotate, just show what would be done |
-s, --state FILE | Use an alternate state file (default: /var/lib/logrotate/status) |
-m, --mail COMMAND | Use COMMAND instead of /bin/mail for sending rotated files |
-l, --log FILE | Log all actions to FILE for debugging and auditing |
-p, --pid FILE | Write PID to FILE to prevent concurrent executions |
-S, --skipglobs | Skip files matching glob patterns |
Examples
Execute logrotate with the default configuration file
logrotate /etc/logrotate.confForce rotation of all configured logs immediately
logrotate -f /etc/logrotate.confDebug mode: show what would be rotated without actually doing it
logrotate -d /etc/logrotate.confVerbose mode: print detailed information about rotation actions
logrotate -v /etc/logrotate.confRun logrotate and log all actions to a specified log file
logrotate -l /var/log/logrotate.log /etc/logrotate.confUse an alternate state file to track last rotation timestamps
logrotate -s /tmp/logrotate.state /etc/logrotate.conf