shell腳本中特殊篩選文件

問題描述:在寫shell中,總會遇到一些各式各樣篩選文件的需求,整理了一些特殊情況

 

1.查找目標文件下大於100Mb的文件

find $target_dir -type f -size +70M

 

2.查找目標文件下大於100Mb的文件,並顯示詳細信息

find $target_dir -type f -size +300M  -print0 | xargs -0 ls -ltrh

 

3.查找文件不缺分大小寫

find $target_dir -iname "$file*.zip"

 

4.查找目標文件下所有的*.zip文件,並且排除掉幾個目標*.zip文件

find $target_dir -iname "$file*.zip" -type f -mtime +0 -mtime -2 -not -name '*-test.zip' -not -name '*-mysql.zip' -not -name '*-information_schema.zip' -not -name '*-sys.zip'

 

5.查找目標文件下最新的目錄

find $target_dir -type d -printf '%T@ %p\n' | sort -n | tail -n 1 | awk '{print $2}'

 

6.獲取目標文件下最新的一個*.zip文件

ls -ltd $target_dir/* | grep -E all-database-.*zip | head -n1 | awk '{print $9}'

 

7.查找目標文件下7天前的*.zip文件

find $target_dir -iname "all-database-$file*.zip" -type f -mtime +0 -mtime -7

 

8.查找目標文件下的所有文件,目標層級爲0,不向下遞歸

find $target_dir -path test -prune -o -maxdepth 0 -type d

 

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