How To Rotate Log Files In Linux? – POFTUT

How To Rotate Log Files In Linux?

Logs are created by different services like HTTP, FTP, ssh, etc. What do we with these logs? May be nothing but when the times came it will be important to get detailed information about the error, security event etc from log files. Logs are created all times and always grows up. How can we handle to prevent these logs files to fill our disks? Here came the rotate operation or daemon. We can rotate and compress our logs file easily with a simple configuration. Also, information about rotated logs can be emailed to specified recipient.

Default Configuration File

Logrotate default configuration file resides /etc/logrotate.conf . Below is default  configuration details

There are explanations about configuration directives.

Default Configuration File

Default Configuration File

Enable Compression For Rotated Files

Rotating log files create new log file and old files can be compressed to gain disk space like below.

LEARN MORE  Git - Reviewing Changes

Uncomment compress line or add a new line

Change BackLog

How much time we will store old logs? We can set it with count like below.

This will rotate or save log files for 4 weeks if rotation is done weekly. If rotation is done daily it will hold old logs for 4 days.

Specify New Rotate Configuration

We can create a new and different rotate configuration for different logs. New rotate configuration is hold in /etc/logrotate.d/

echo '

As we see there is a lot of logrotate configuration for different logs like samba, httpd, etc.

Leave a Reply

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