Linux – Forcing Log Rotation – Get Past the Frustration

Log Rotation Frustration

In the past, when I would configure log rotation I would try to run it manually so that I could verify that it actually works.  What made it difficult is that it normally logs the file in the log rotation status file and then the next time it runs, it then compares the file needing rotation against the timestamp in the log rotation status file.  What this means is that it could take more than 24 hours to get the file rotated.  This can be extremely frustrating because the reason you are configuring the log rotation in the first place is that you need them rotated now!

Here’s a trick that I learned to force rotation using logrotate.

Before I understood how it worked, I would get frustrated with the logrotate daemon.  It never worked the first night and I could not figure out why.  Now I know.  The first time that it runs, it creates an entry for the file needing rotation in the file below:

/var/lib/logrotate.status (centos)


/var/lib/logrotate/status (ubuntu)

This file specifies the files that it knows about and when they were last rotated.  The first time, it assumes that the files do not need rotation, but adds them to the list.  The next night, if they are set to daily, it will logrotate that night.  If you want to force log rotation immediately after configuring the files in the /etc/logrotate.d directory, run the log rotation manually:

logrotate -v /etc/logrotate.conf

This will make an entry in the log rotate status file (see above for ubuntu and CentOS locations).

Next, edit the /var/lib/logrotate status file listed above for your OS, change the date for that specific file to be one in the past.  Then run the logrotate command again manually:

logrotate -v /etc/logrotate.conf

Now go and check and the file will have rotated.  From this point on, whenever I add a new file or directory of files to rotate, I am forcing log rotation using these steps to get past the frustration!


The following two tabs change content below.
Jeff has 20 years of professional IT experience, having done nearly everything in his roles of IT consultant, Systems Integrator, Systems Engineer, CNOC Engineer, Systems Administrator, Network Systems Administrator, and IT Director. If there is one thing he knows for sure, it is that there is always a simple answer to every IT problem and that downtime begins with complexity. Seasoned IT professional by day, Jeff hopes to help other IT professionals by blogging about his experiences at night on his blog: You can find Jeff on or LinkedIn at: LinkedIn or Twitter at: Twitter

Latest posts by Jeff Staten (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *