簡體   English   中英

從查找中排除子目錄

[英]Exclude sub directory from find

我有以下類似的結構。

$ tree ./tmp
./tmp
├── file.ext
├── file.other_ext
└── inner_tmp
    ├── inner_file.ext
    └── inner_file.other_ext

1 directory, 4 files
$

當我嘗試

$ find./tmp -type f -name '*.ext' -not -path './inner_tmp/'

或者

$ find./tmp -path './inner_tmp/*' -prune -o -type f -name '*.ext' -print

我得到以下信息:

./tmp/inner_tmp/inner_file.ext
./tmp/file.ext

問題是:為什么inner_tmp目錄包含在結果中? 我在這里想念什么?

在這種情況下./inner_tmp將不匹配任何路徑,因為您指定為起點的路徑是./tmp ,因此所有要找到的路徑都將以./tmp

試試這個:

find ./tmp ! \( -path './tmp/inner_tmp' -prune \) -type f -name '*.ext'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM