find查找文件的时候排除某个或几个文件或目录
生活随笔
收集整理的這篇文章主要介紹了
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
避開多個文件夾
?
find /usr/sam \( -path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -print圓括號表示表達式的結合。
查找某一確定文件,-name等選項加在-o 之后
?
#find /usr/sam \(-path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -name "temp" -print轉載于:https://www.cnblogs.com/starspace/archive/2008/10/20/1315380.html
總結
以上是生活随笔為你收集整理的find查找文件的时候排除某个或几个文件或目录的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: What do you need at
- 下一篇: 成为软件架构师的4个过程