刪除文件夾中文件名含有“badcase”的文件:
- 首先找到這些文件
- 然後加刪除命令
- 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