http://blog.csdn.net/ysdaniel/article/details/7995681
查找cache目錄下不是html的文件
- find ./cache ! -name '*.html' -type f
列出當前目錄下的目錄名,排除includes目錄,后面的-print不能少
- find . -path './includes' -prune -o -type d -maxdepth 1 -print
排除多個目錄,”(“前是帶”\”的
- find / \( -path /home/ -o -path /root \) -prune -nouser -type f -exec ls -l {} \;
?
find查找文件的時候排除某個或幾個文件或目錄
比如要在/usr/sam目錄下查找不在dir1子目錄之內的所有文件
?
find /usr/sam -path "/usr/sam/dir1" -prune -o -print
?
?
find [-path ..] [expression] 在路徑列表的后面的是表達式
?
-path "/usr/sam" -prune -o -print 是 -path "/usr/sam" -a -prune -o -print 的簡寫表達式按順序求值, -a 和 -o 都是短路求值,與 shell 的 && 和 || 類似如果 -path "/usr/sam" 為真,則求值 -prune , -prune 返回真,與邏輯表達式為真;否則不求值 -prune,與邏輯表達式為假。如果 -path "/usr/sam" -a -prune 為假,則求值 -print ,-print返回真,或邏輯表達式為真;否則不求值 -print,或邏輯表達式為真。
這個表達式組合特例可以用偽碼寫為
?
if -path "/usr/sam" then
?????????? -prune
else
?????????? -print
?
避開多個文件夾
?
find /usr/sam \( -path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -print
?
圓括號表示表達式的結合。
\ 表示引用,即指示 shell 不對后面的字符作特殊解釋,而留給 find 命令去解釋其意義。
?
查找某一確定文件,-name等選項加在-o 之后
?
#find /usr/sam \(-path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -name "temp" -print
?
linux下的常用命令find,加上不同的參數,可以使你很容易的找到需要的文件,但是有些時候,你在查找文件的同時,可能不需要在某文件夾下查找,這時候-prune就用上了。
比如在當前目錄下尋找pl后綴的文件,不在scripts下尋找。
find . -path './scripts' -prune -o -name '*.pl' -print