Keeping log files under control

My recent issue with low levels of disk space (see: Low disk space warning), and the subsequent fix of deleting a number of log files, started me thinking about how to stop multiple, large, log files that I never (well – very rarely) use from being created in the first place. I eventually located a web posting that discusses configuring the /etc/logrotate.conf file to reduce both the size of various log files and the number of such archived files.

The log rotation process automatically saves a copy of a log file after a defined period (e.g. one day, week, or month), creates a blank log file for future entries, can compress saved log files in order to save disk space, and will remove a saved log file after a certain number of “rotations” of the log files have taken place (e.g. after copies of the past five log files have been saved). The log rotation process has many other options (see: man logrotate).

One way to reduce the file size is to rotate the log files each day rather than letting the entries build up over the default weekly setting. The relevant lines in the logrotate.conf file are:

# rotate log files weekly

The file can be edited (sudo gedit /etc/logrotate.conf) to change these lines to:

# rotate log files daily

Reducing the log file size further can be achieved by storing the historical files in compressed format. The logrotate.conf file contains the lines:

# uncomment this if you want your log files compressed

As the comment indicates, one simply removes the comment tag from the second line so as to leave this command as:


Reducing the number of saved files (reducing the rotation frequency) is simply a matter of changing two subsequent lines:

#keep 4 weeks worth of backlogs
rotate 4

to something like:

# keep 1 weeks worth of backlogs
rotate 1

As noted, log rotation provides many options, so pick a set that suit your system – and save some disk space!.


Log files gobbling up all free disk space

Manage Linux log files with Logrotate

This entry was posted in Tweaks and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s