简体   繁体   English

从查找中排除子目录

[英]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.

相关问题 从查找中排除子目录:为什么 -not -path 不起作用? - Exclude sub directories from find: why is -not -path not working? 如何在目录中递归查找特定文件,通过在子目录名称前添加前缀将其重命名,然后将其移动到其他目录 - How to find a specific files recursively in the directory, rename it by prefixing sub-directory name, and move it to different directory 如何排除./。 从shell脚本搜索目录? - How do I exclude a ./. directory from a shell script search? 在这种情况下,我如何排除一个以上的目录...找到./dir1 -name'.git'-prune - how do i exclude more that one directory in this case … find ./dir1 -name '.git' -prune bash:从给定子目录名称的当前目录获取路径 - bash: get path from current directory given sub-directory name 如何从 Bash Mac 查找中排除包文件(目录)? - How Do I Exclude Package Files (Directories) from Bash Mac find? 如何从目录ID和卷号中找到FSRef? - How to find an FSRef from a directory ID and a volume number? 从macdeployqt中排除框架 - Exclude Frameworks from macdeployqt 如何找到运行python脚本的.app目录 - How to find the directory of the .app that a python script is running from 从文件名的CSV文件中,找到并打开一个文件夹(或子文件夹)中的多个文件 - from a CSV of filenames, find and open multiple files in a folder (or sub-folders)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM