[英]Exclude sub directory from find
I have the following similar structure.我有以下类似的结构。
$ tree ./tmp
./tmp
├── file.ext
├── file.other_ext
└── inner_tmp
├── inner_file.ext
└── inner_file.other_ext
1 directory, 4 files
$
When I try当我尝试
$ find./tmp -type f -name '*.ext' -not -path './inner_tmp/'
OR或者
$ find./tmp -path './inner_tmp/*' -prune -o -type f -name '*.ext' -print
I get the following:我得到以下信息:
./tmp/inner_tmp/inner_file.ext
./tmp/file.ext
The question is: Why inner_tmp
directory is included in result?问题是:为什么inner_tmp
目录包含在结果中? What am I missing here?我在这里想念什么?
./inner_tmp
will not match any path in this case, for the path you specified as starting point is ./tmp
, so all paths to be found will start with ./tmp
.在这种情况下./inner_tmp
将不匹配任何路径,因为您指定为起点的路径是./tmp
,因此所有要找到的路径都将以./tmp
。
Try this instead:试试这个:
find ./tmp ! \( -path './tmp/inner_tmp' -prune \) -type f -name '*.ext'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.