使用過 Windows 的人都知道,在使用 windows 系統的過程中系統會變得越來越慢。而對於 Windows 下飽受詬病的各種垃圾檔案都需要自己想辦法刪除,不然系統將會變得越來越大,越來越遲鈍!windows 怎麼清理垃圾相信大家都知道的,那麼 linux 下怎麼清理系統垃圾呢?
Linux 的檔案系統比 Windows 的要優秀,不會產生碎片,對於長時間執行的站群伺服器來說尤為重要,而且 Linux 系統本身也不會像 Windows 一樣產生大量的垃圾檔案。不知道這個說法有沒有可信度!至少我們可以確定的是 linux 系統的檔案系統是比較優秀的!
錯誤
rm -f logfile
原因
應用已經開啟檔案控制程式碼,直接刪除會造成:
1. 應用無法正確釋放日誌檔案和寫入
2. 顯示磁碟空間未釋放
正確
cat /dev/null >logfile
把一下程式碼儲存為.sh 字尾指令碼來執行即可清除 Linux 系統日誌
#!/bin/sh
cat /dev/null >/var/log/syslog
cat /dev/null >/var/adm/sylog
cat /dev/null >/var/log/wtmp
cat /dev/null >/var/log/maillog
cat /dev/null >/var/log/messages
cat /dev/null >/var/log/openwebmail.log
cat /dev/null >/var/log/maillog
cat /dev/null >/var/log/secure
cat /dev/null >/var/log/httpd/error_log
cat /dev/null >/var/log/httpd/ssl_error_log
cat /dev/null >/var/log/httpd/ssl_request_log
cat /dev/null >/var/log/httpd/ssl_access_log
另外清理 linux 系統垃圾還有以下命令
sudo apt-get autoclean 清理舊版本的站群軟體 WordPress 加速快取
sudo apt-get clean 清理所有站群軟體 WordPress 加速快取
sudo apt-get autoremove 刪除系統不再使用的孤立站群軟體