linux的一個find命令配合rm刪除某天前的檔案__linux

來源:互聯網
上載者:User

語句寫法:find 對應目錄 -mtime +天數 -name "檔案名稱" -exec rm -rf {} \;

 例1: 將/usr/local/backups目錄下所有10天前帶"."的檔案刪除

  find /usr/local/backups -mtime +10 -name "*.*" -exec rm -rf {} \;

 

  find:linux的尋找命令,使用者尋找指定條件的檔案

  /usr/local/backups:想要進行清理的任意目錄

  -mtime:標準語句寫法

  +10:尋找10天前的檔案,這裡用數字代表天數,+30表示尋找30天前的檔案

  "*.*":希望尋找的資料類型,"*.jpg"表示尋找副檔名為jpg的所有檔案,"*"表示尋找所有檔案,這個可以靈活運用,舉一反三

  -exec:固定寫法

  rm -rf:強制移除檔案,包括目錄

  {} \; :固定寫法,一對大括弧+空格+\

 

find $1 -name "*.html" -mtime +1 -print0 |xargs -0 rm -v

刪除最近一天的檔案:

find ./ -mtime -1 -print -exec rm -f {} \;  


轉載地址:http://www.cnblogs.com/mingforyou/p/3930624.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.