find命令的學習使用

1.
     find . -print
     # 打印文件和目錄的列表

2.   
find . -name "*.stackdump" | xargs rm
#查找後綴名爲stackdump的文件並刪除

3.
find . \( -name "*.hpp" -o -name "*.h" \) -print
#匹配多個條件,使用“OR”組合條件。以上命令查找後綴名爲".hpp"與".h"的文件。

4.
find . -path "*tmp*" -print
#查找文件路徑名以tmp結尾的的文件夾或文件

5.
find . -regex ".*\(\.py\|\.sh\)$"
#使用正則表達式模式查找文件

6.
find . ! -name "*.cpp" -print
#匹配所有不以.cpp結尾的文件名

7.
find . -maxdepth 1 -type d -print
#查找深度爲1的目錄(當前目錄)下的所有文件類型爲d(及文件夾)的文件並打印。

8.
find . -maxdepth 2 -name "*.cpp" -print
#查找深度爲2的目錄(當前目錄的下一級目錄)下所有後綴名爲”.cpp“的文件並打印。

9.
find . -mindepth 2 -type f -print
#查找距離當前深度至少爲2的文件並打印。


10.
find . -type l -print
#查找文件類型爲符號鏈接類型的文件並打印。

11.
find . -type f -atime -7 -print
#查找最近7天被訪問過的所有文件

12.
find . -type f -atime 7 -print
#查找恰好在七天前被訪問的所有文件

13.
find . -type f -atime +7 -print
#打印出訪問時間超過七天的所有文件


14.
find . -type f -amin -30 -print
#打印訪問時間少於30分鐘的所有文件

15.
find . -type f -size +20M
#查找當前目錄下文件大小大於20MB的文件


16.
find . -type f -size -1k
#查找當前目錄下文件大小小於1KB的文件

17.
find . -type f -size 4k
#查找當前目錄下文件大小等於4KB的文件

文件大小:b-塊,c-字節,w-字(2字節),k-千字節,M-兆字節,G-吉字節。

18.
find . -type f -name "*.swp" -delete
#刪除當前目錄下的所有.swp文件

19.
find . -type f -user frank -print
#查找文件所有者爲frank的所有文件

20.
find . -type f -perm 644 -print
#查找文件權限爲644的所有文件

21.
find . -type f -name "*.c" -exec cat {} \;>all_c_files.txt
#查找所有.c文件並拼接起來寫入all_c_files.txt文件


22.
find . -type f -name "*.txt" -exec printf "Text file: %s\n" {} \;
#-exec能夠同printf結合起來生成有用的輸出信息。

23.
find . \( -name ".git" -prune \) -o \( -type f -print \)
#打印出不包含在.git目錄下的所有文件的名稱(路徑)。



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