How To Logrotate in Linux

Logrotate is a handy tool for system administrators who wish to take the /var/log directory under their control. The logrotate command is called daily by the cron scheduler and it reads the following files:

  • the logrotate configuration file /etc/logrotate.conf
  • files in the logrotate configuration directory /etc/logrotate.d Most of the services (Apache webserver, postgreSQL, MySql, KDE desktop manager etc.) installed on your system create a configuration file for logrotate in /etc/logrotate.d. For example here are the contents of my /etc/logrotate.d directory:



#ls -al

I have created a File calles raw, which rotate my raw syslog messages

My raw log stored under /var/syslog-ng/raw/alldevices.log

Rotate 20 – keep 20 archives

create 0644 root root – create new file with 644 permittion as owner root

daily – run daily once

no commress – its rotate as it is ( it will not compress, if need use compress).

missingok – If the log file is missing, go on to the next one without issuing an error message.

save the file as mentioned

cp the file in to /etc/logrotate.d

change the ownership

chmod 0644 raw

chown root root raw


logrotate -f /etc/logrotate.d/raw you should not see any errors.

go to directory and see the archive created or not.

Note : above you can see compress also i have tested compress also.

hope you enjoyed, Happy Labbiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiing !!