繁体   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