centos7 日志清理

使用CentOS系统的时候,经常会遇到系统日志文件非常大的情况,如果直接删除,会导致日志错误,不再生成日志,这时,我们可以使用下面的方法清空日志。

cat /dev/null > /var/log/boot.log
cat /dev/null > /var/log/btmp
cat /dev/null > /var/log/cron
cat /dev/null > /var/log/dmesg
cat /dev/null > /var/log/firewalld
cat /dev/null > /var/log/grubby
cat /dev/null > /var/log/lastlog
cat /dev/null > /var/log/mail.info
cat /dev/null > /var/log/maillog
cat /dev/null > /var/log/messages
cat /dev/null > /var/log/secure
cat /dev/null > /var/log/spooler
cat /dev/null > /var/log/syslog
cat /dev/null > /var/log/tallylog
cat /dev/null > /var/log/wpa_supplicant.log
cat /dev/null > /var/log/wtmp
cat /dev/null > /var/log/yum.log

/dev/null

在Linux/Unix中,一般在屏幕上面看到的信息是从stdout (standard output) 或者 stderr (standard error output) 来的。
许多人会问,output 就是 output,送到屏幕上不就得了,为什么还要分成stdout 和 stderr 呢?那是因为通常在 server 的工作环境下,几乎所有的程序都是 run 在 background 的,所以呢,为了方便 debug,一般在设计程序时,就把 stdout 送到/存到一个档案,把错误的信息 stderr 存到不同的档案。
那什么是 /dev/null呢,/dev/null 是 Unix/Linux 里的【无底洞】任何的 output 送去了【无底洞】就再也没了。相信我,真的没了!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章