Using logrotate as a Generic Log Rotation Tool

Red Hat Linux runs the logrotate program as a daily cron job to maintain its own log files, but few people take advantage of logrotate to manage their own application logs. Information pertaining to each log and its rotation policies are stored in a configuration file: /etc/logrotate.conf by default. To maintain state between runs, logrotate stores the time of the last rotation of each log in a “state file,” /var/lib/logrotate.status on Red Hat Linux. The state file ensures that logrotate does not rotate logs more than once per day, just in case an administrator accidentally runs it more than once.

logrotate has a very simple syntax, as follows:

logrotate [-dv] [-f|--force] [-s|--state state-file ...

Get Unix® System Management Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.