Linux下清除系統日誌方法__Linux

來源:互聯網
上載者:User

摘要:相信大家都是用過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 清理舊版本的軟體緩衝
sudo apt-get clean 清理所有軟體緩衝
sudo apt-get autoremove 刪除系統不再使用的孤立軟體

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.