文章目录[隐藏]
linux服务器用久了,会产生很多日志。如果服务器空间比较小,又没有定期清除,很快硬盘就会满了。这个时候就需要删除服务器上的日志。
本篇文章适用于centos系统:
1. 进入服务器后,先切换到根目录
cd /
2. 使用命令 du -sh ./* ,可以看到当前目录的文件或文件夹大小。
du -sh ./*
3. 进入到 /var文件夹下,继续使用 du -sh ./* 命令,可以看到log文件夹比较大。日志文件一般都放在这个目录下面。
4. 进入到log文件夹,继续使用 du -sh ./* 命令,删除比较大的文件。
如btmp, secure文件。绝对路径为 /var/log/btmp,/var/log/secure
命令如下。
rm -rf /var/log/btmp touch /var/log/btmp rm -rf /var/log/secure touch /var/log/secure
当然还有一些日志文件也可以删除,有网友整理了这些文件。
CentOS 6系统
/var/log/boot.log /var/log/btmp /var/log/cron /var/log/dmesg /var/log/dracut.log /var/log/lastlog /var/log/maillog /var/log/messages /var/log/secure /var/log/spooler /var/log/tallylog /var/log/wtmp /var/log/yum.log
linux执行命令
rm -rf /var/log/boot.log touch /var/log/boot.log rm -rf /var/log/btmp touch /var/log/btmp rm -rf /var/log/cron touch /var/log/cron rm -rf /var/log/dmesg touch /var/log/dmesg rm -rf /var/log/dracut.log touch /var/log/dracut.log rm -rf /var/log/lastlog touch /var/log/lastlog rm -rf /var/log/maillog touch /var/log/maillog rm -rf /var/log/messages touch /var/log/messages rm -rf /var/log/secure touch /var/log/secure rm -rf /var/log/spooler touch /var/log/spooler rm -rf /var/log/tallylog touch /var/log/tallylog rm -rf /var/log/wtmp touch /var/log/wtmp rm -rf /var/log/yum.log touch /var/log/yum.log
CentOS 7系统
/var/log/boot.log /var/log/btmp /var/log/cron /var/log/dmesg /var/log/firewalld /var/log/grubby /var/log/lastlog /var/log/mail.info /var/log/maillog /var/log/messages /var/log/secure /var/log/spooler /var/log/syslog /var/log/tallylog /var/log/wpa_supplicant.log /var/log/wtmp /var/log/yum.log
执行命令
rm -rf /var/log/boot.log touch /var/log/boot.log rm -rf /var/log/btmp touch /var/log/btmp rm -rf /var/log/cron touch /var/log/cron rm -rf /var/log/dmesg touch /var/log/dmesg rm -rf /var/log/firewalld touch /var/log/firewalld rm -rf /var/log/grubby touch /var/log/grubby rm -rf /var/log/lastlog touch /var/log/lastlog rm -rf /var/log/mail.info touch /var/log/mail.info rm -rf /var/log/maillog touch /var/log/maillog rm -rf /var/log/messages touch /var/log/messages rm -rf /var/log/secure touch /var/log/secure rm -rf /var/log/spooler touch /var/log/spooler rm -rf /var/log/syslog touch /var/log/syslog rm -rf /var/log/tallylog touch /var/log/tallylog rm -rf /var/log/wpa_supplicant.log touch /var/log/wpa_supplicant.log rm -rf /var/log/wtmp touch /var/log/wtmp rm -rf /var/log/yum.log touch /var/log/yum.log
这些文件都可以安全删除。