How is logrotate used in Linux?
Logrotate is a tool commonly used in Linux systems to periodically rotate, compress, and delete log files in order to prevent system performance degradation due to oversized log files.
Here are the basic usage guidelines:
- Edit the logrotate configuration file, which is typically located in the /etc/logrotate.conf or /etc/logrotate.d/ directory, with each log file having its own corresponding configuration file.
- Set rotation rules: Configure the frequency, number of copies, compression method, etc. of log file rotation in the configuration file.
- Manually run logrotate: You can manually run logrotate to rotate log files using the command “logrotate -f /path/to/configfile”.
- Automatic scheduling rotation: logrotate can also automatically perform rotation operations through cron scheduled tasks, which can be set in files such as /etc/cron.daily/logrotate.
By using logrotate, you can effectively manage log files, save disk space, and prevent large log files from affecting system performance.