简体   繁体   中英

Exclude sub directories from find: why is -not -path not working?

java -jar ~/Downloads/simian-2.3.35/bin/simian-2.3.35.jar files $(find ~/App/Classes/ -type f -name "*.m"  -not -path  "Lib/excludethisdir/*")

I'm trying to run simian and pass a file argument into it, but excluding a directory just isn't working. The Lib directory is contained in Classes

Can anyone point out why it's not working (The command runs, but it doesn't exclude)

You nested find command should be:

find ~/App/Classes/ -type f -name "*.m"  -not -path "./Lib/excludethisdir/*"

ie add ./ before your excluded path.

Or even better:

find ~/App/Classes/ -path "./Lib/excludethisdir/*" -prune -o -type f -name "*.m" -print

It is NOT and answer! 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?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM