Automatically rotate, compress, and manage log files.
low risk
logrotate manages log file rotation on a schedule — compressing old logs, deleting logs older than N days, and sending signals to services to reopen log files. Config in /etc/logrotate.conf and /etc/logrotate.d/. Run by cron or systemd timer daily.
| Flag | Meaning |
|---|---|
-d --debug | Dry run — show what would happen without doing it |
-f --force | Force rotation even if not due |
-v --verbose | Verbose output |
logrotate -d /etc/logrotate.d/nginxDry run nginx log rotation config · explain & risk-check →logrotate -f /etc/logrotate.confForce rotate all logs immediately · explain & risk-check →logrotate -v /etc/logrotate.d/myappVerbose rotation for debugging · explain & risk-check →cat /etc/logrotate.d/nginxView nginx logrotate config · explain & risk-check →Always test new logrotate configs with `-d` (dry run) first. Common mistake: missing `postrotate` signal to the daemon to reopen files — without it, the service keeps writing to the rotated file.
Reference text is hand-written and may be incomplete — check man logrotate for your version. Test destructive commands on a non-production system first.