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? 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
.
Try this instead:
find ./tmp ! \( -path './tmp/inner_tmp' -prune \) -type f -name '*.ext'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.