Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

find 排除子目錄的查詢寫法

find 排除子目錄的方法有很多,下面這個寫法特別好用:

find . ! -name "." -type d -prune -o -type f -name "*.txt" -print

它只會列出當前目錄下的 .txt,不下探子目錄(相較之下,直接 find . -name "*.txt" 會把 RPM/ 等子目錄的檔案也列出來)。

另一種寫法:maxdepth

find . -maxdepth 1 -name '*.txt'

-maxdepth 1 限制只搜尋一層,效果相同且更直觀。

Copyright © Linux教程網 All Rights Reserved