linux系統刪除滿足特定條件的文件

刪除文件夾中文件名含有“badcase”的文件:

  1. 首先找到這些文件
  2. 然後加刪除命令
  3. xargs代表把前面的當作後面命令的輸出

find . -maxdepth 1  -regex ".*badcase.csv*" 

find . -maxdepth 1  -regex ".*badcase.csv*"   -exec rm -rf {} \;

或 find . -maxdepth 1  -regex ".*badcase.csv*" | xargs rm -rf 

顯示20分鐘前的文件
find /home/prestat/bills/test -type f -mmin +20 -exec ls -l {} \;

刪除20分鐘前的文件
find /home/prestat/bills/test -type f -mmin +20 -exec rm {} \;

顯示20天前的目錄
find /home/prestat/bills/test -type d -mtime +20 -exec ls -l {} \;

刪除20天前的目錄
find /home/prestat/bills/test -type d -mtime +20 -exec rm {} \;

 

在20-50天內修改過的文件

find ./ -mtime +20 -a -mtime -50 -type f

 

參考:https://blog.csdn.net/xueyingxue001/article/details/51498902 

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