Logrotate on Ubuntu: Configuration Examples & Reference

Last updated:

WIP ALERT This is a Work in Progress

Rotating log files means compressing and changing the name of a old log files ( say foo.conf) to something like foo.conf.1.gz so that it takes less space and applications that depend on foo.conf existing will not crash.

Also, there is less risk that the system will run out out space.

The main configuration file is /etc/logrotate.conf, but if you want to add new rules or update existing one, change the files in /etc/logrotate.d/ instead.

Configuration files under /etc/logrotate.d/ are included in the main configuration file

Example 1

All files that end in .log under /var/log/somefolder/ will be rotated every month (or when they reach 100M in size). The system will keep up to 52 compressed copies (will delete older copies).

/var/log/somefolder/*.log {
    size 100M
    rotate 52
    create 640 root adm

See also

Dialogue & Discussion