$linuxjunkies
>

logrotate(8)

Rotates, compresses, and removes old log files based on rules configured in /etc/logrotate.conf and /etc/logrotate.d/.

UbuntuDebianFedoraArch

Synopsis

logrotate [OPTION]... CONFIG_FILE

Description

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

FlagWhat it does
-f, --forceForce rotation of all log files, regardless of rotation conditions
-v, --verbosePrint informational messages about what is being done
-d, --debugDebug mode; do not actually rotate, just show what would be done
-s, --state FILEUse an alternate state file (default: /var/lib/logrotate/status)
-m, --mail COMMANDUse COMMAND instead of /bin/mail for sending rotated files
-l, --log FILELog all actions to FILE for debugging and auditing
-p, --pid FILEWrite PID to FILE to prevent concurrent executions
-S, --skipglobsSkip files matching glob patterns

Examples

Execute logrotate with the default configuration file

logrotate /etc/logrotate.conf

Force rotation of all configured logs immediately

logrotate -f /etc/logrotate.conf

Debug mode: show what would be rotated without actually doing it

logrotate -d /etc/logrotate.conf

Verbose mode: print detailed information about rotation actions

logrotate -v /etc/logrotate.conf

Run logrotate and log all actions to a specified log file

logrotate -l /var/log/logrotate.log /etc/logrotate.conf

Use an alternate state file to track last rotation timestamps

logrotate -s /tmp/logrotate.state /etc/logrotate.conf

Related commands