Log Rotate

General Information

  • The package “logrotate” is installed by default on most linux distros.
  • Logrotate is executed via a daily cron job: /etc/cron.daily/logrotate


  • Distro(s): Enterprise Linux 6

Forcing a log rotation can be useful after implementing a new rotation file (in /etc/logrotate.d) or to test after making changes.

  • To force a logrotate using a specific config file
    • /usr/sbin/logrotate -f /etc/logrotate.d/myapp
  • To force a logrotate of ALL log files
    • /usr/sbin/logrotate -f /etc/logrotate.conf

/etc/logrotate.conf is left alone in its default installed state.

Ensure that /etc/logrotate.d is included (it is by default):

include /etc/logrotate.d

All additional log configuration files go in: /etc/logrotate.d/

Example Log Config

## Application Logs ##
/opt/myapp/logs/logs.txt {
  #Rotate monthly
  #Keep 12 old log files, delete older
  rotate 12
  #Copy current log to rotated, then truncate in place
  #Give rotated log file a date extension YYYYMMDD
  #Compress old log files with gzip

  • linux_wiki/log_rotate.txt
  • Last modified: 2019/05/25 23:50
  • (external edit)