Linux command
logrotate 命令
安全
权限或系统影响较大,执行前请核对目标。
常用示例
Force
sudo logrotate --force [/etc/logrotate.conf]
Debug mode
logrotate --debug [/etc/logrotate.conf]
Verbose
sudo logrotate --verbose [/etc/logrotate.conf]
Example
sudo logrotate --state [/var/lib/logrotate/status] [/etc/logrotate.conf]
Log verbose
sudo logrotate --verbose --log [/var/log/logrotate.log] [/etc/logrotate.conf]
说明
logrotate manages log files by rotating, compressing, removing, and mailing them. It prevents logs from consuming excessive disk space and is typically run daily via cron.
参数
- -f, --force
- Force rotation even if conditions are not met
- -d, --debug
- Debug mode; show what would happen without making changes
- -v, --verbose
- Verbose output
- -s, --state _FILE_
- Use alternate state file (default: /var/lib/logrotate/status)
- -l, --log _FILE_
- Log verbose output to file
- --mail _COMMAND_
- Use specified command to mail logs
FAQ
What is the logrotate command used for?
logrotate manages log files by rotating, compressing, removing, and mailing them. It prevents logs from consuming excessive disk space and is typically run daily via cron.
How do I run a basic logrotate example?
Run `sudo logrotate --force [/etc/logrotate.conf]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -f, --force do in logrotate?
Force rotation even if conditions are not met