How do I rotate log files?

How do I rotate log files?

To rotate log files on a Linux or Unix system, you can use the "logrotate" utility. "logrotate" is a command-line utility that allows you to rotate, compress, and delete old log files based on certain criteria, such as the size of the log file or the age of the log file.

To rotate log files using "logrotate", follow these steps:

  1. Open a terminal and log in as the "root" user or a user with root privileges.

  2. Navigate to the directory where the "logrotate" configuration file is located. On most systems, this is the "/etc/logrotate.conf" file.

  3. Edit the "logrotate" configuration file to specify the log files you want to rotate and the criteria for rotating them. For example:

/var/log/syslog {
    rotate 7
    daily
    compress
    delaycompress
    missingok
}
Source:‮ttual.www‬uri.com

This configuration will rotate the "/var/log/syslog" log file daily, keep the last 7 rotated log files, compress the rotated log files, and skip the rotation if the log file is missing.

  1. Save the "logrotate" configuration file and exit the editor.

  2. Run the "logrotate" command to rotate the log files based on the configuration in the "logrotate" configuration file.

logrotate /etc/logrotate.conf

With these steps, you should be able to rotate log files on a Linux or Unix system using the "logrotate" utility. Consult the documentation of "logrotate" for more information on how to use this utility and configure the rotation of log files.

Created Time:2017-10-28 21:38:56  Author:lautturi