13 March 2019

How to run logrotate for a specific log file

An extract from the web page http://www.thecave.info/execute-logrotate-command-manually/

Execute Logrotate Command Manually

I needed to rotate a log file that was filled with duplicate lines, and had filled the / directory. The syslog file was now 180GB in size. (a nouveau issue in Linux lite 4 caused this)   I knew that the compressed log file would be very small as the gigabytes of duplicate lines in syslog would compress to nothing. (eventually it was 11MB after compression)
The following extract/example is forcing the apache2 log file to rotate. I needed the syslog file to be rotated. The first job was to free up as much space as possible in order to allow the log rotate action to take place. This involved moving, or deleting all large files in my home directory, and deleting any archived log files that were large enough to make a difference.
I used the following command for syslog


  1. logrotate -vf /etc/logrotate.d/rsyslog

The extract from the previously mentioned web page where his problem is the apache log follows:-

Since most of my disk space was consumed by apache, I decided to execute logrotate command manually in linux and pass it the config of the logrotate apache . To do so, I used the following command:
  1. logrotate -vf /etc/logrotate.d/apache2.conf
The flags ‘-vf’ passed to the command are as follows:
  • -v verbose shows more information. useful to try detect any errors there may be with logrotate
  • -f force the rotation to occur even if it is not necessarily needed
And /etc/logrotate.d/apache2.conf is the location of my config file of for the apache2