Here are a couple of good links about using find:
The basic syntax of a find
command is like this:
find <starting dirs> <global options> <matching expressions> <actions> [-a/-o <matching expressions> <actions>]
There can be multiple entries for all of these.
One thing to understand about -prune
is that it's an action
. That is, it removes from consideration all the files matched by the expressions in front of it. So to fully use it, you also need to include a second expression that does what you want with the rest of the files.
A second thing to watch out for is that the default action (print) only works if there's a single matching expression to operate on. When you have multiple sets of matching expressions, each one must have its actions explicitly
provided, and generally grouped with \(..\)
brackets (see the last section of my first link).
So what you really want is something more like this:
find . ! \( -path "*/a2/*" -prune \) -o \( -type f -print \)
Although actually I don't think even this is necessary for most of your needs. Since it all comes down to a properly matching -path
expression anyway, just use that directly:
find . -type f -path "*/a2/*" -print
find . -type f -path "./[b-z]/* -print
Be aware that some options like -name
patterns, while others like -regex
use regular expressions
. Check the find