How can I rotate my application logs periodically in Red Hat Enterprise Linux?

Red Hat Enterprise Linux has a daily cron job named logrotate which runs /usr/sbin/logrotate /etc/logrotate.conf every day. it is designed to ease administration of systems that generate large numbers of log files.

This job will first import all the policy files in directory of /etc/logrotate.d/ and do as the config file ask to, For example, /etc/logrotate.dsyslog defines /var/log/messages to be rotated weekly.

Suppose there is a log file /var/log/app_log which needs to be rotated every day, this is the example config file to make that happen (/etc/logrotate.d/app_log):

[root@dhcp-0-130 ~]# cat /etc/logrotate.d/app_log
/var/log/app_log {
rotate 2

rotate #

means log files are rotated times before being removed.


means log files are rotated every day.

Hope you got a glimpse of power of LinuX.

Happy Logging !!

No comments:

Post a Comment