我有两个目录(~/www/ 和 ~/client-sites/),其中包含一堆站点,每个站点都有 access.log 和 error.log 文件。
找到所有这些文件并清空其内容的最简单方法是什么?它们增长很快,所以我想每个月左右清除一次日志。
安装 logrotate(Windows 见http://sourceforge.net/projects/logrotatewin):
# CentOS/RHEL
yum install logrotate
# Debian/Ubuntu
apt-get install logrotate
Run Code Online (Sandbox Code Playgroud)
Create/Edit /etc/logrotate.d/httpd,示例取自 CentOS,其他发行版需要调整。
/var/log/httpd/*_log {
weekly
missingok
rotate 5
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
/etc/init.d/httpd reload > /dev/null
endscript
}
Run Code Online (Sandbox Code Playgroud)