Skip to content


logrotate is a utility that is generally always installed on servers and in the true Unix tradition, it has one simple job and it does it well.

What does logrotate Do?

What it does is allow you to freely log to a specific file location, but for that log file to be "rotated" which stops it from just growing in size indefinitely.

The rotation logic is configurable, but in general there will be one active log file that is still having things appenedd to it, and then an archive of other log files, often compressed. Once a log file archive gets beyond a certain age or number then it will be removed. This means that in general the amount of disk space being consumed by a particular log should stay roughly the same.

Generally your server or system will already have a bunch of things configured for logrotate to handle, however you can also add your own.


The configuration files for logrotate jobs generally reside in /etc/logrotate.d

For example:

/var/log/nginx/*log {
    su nginx nginx
    rotate 5
    size 1000k
    create 640 root root
      [ ! -f /var/run/ ] || kill -USR1 `cat /var/run/`

The file format is quite simple. The first line is a glob, generally ending in *log. Don't ever have one that ends with * otherwise you will try to rotate already rotated things!

Then we have a block wrapped in { } and inside here we have the configuration parameters.

To get the full list of configuration directives you can use, you should look at man logrotate

Further Reading

Creating your Own

First, have a read through the man page and reference some other config files.

Next, your starting file contents should look like this:



This assumes the files you want to rotate have a log extension

The directives are up to you, but a fairly standard set might look like:

  rotate 7
  create 660 username username


You have 2 main ways of testing:

Dry Run

If you want to test your file without doing anything then use the -d flag to logrotate:

logrotate -d /etc/logrotate.d/mylogrotatefile

Run Verbose

If you want to actually run it but get debugging output, try

logrotate -d /etc/logrotate.d/mylogrotatefile