I'd like to search a directory tree for regular files matching particular patterns, e.g.
find -regex '.*\.\(expect\|missing\|ok\)'
This is fine, but in my application it is very inefficient -- since if a directory contains at least one matching file, then none of its (many, deep, file-laden) subdirectories need to be searched, since they definitely won't contain any matches.
So how do I -prune
subdirectories, only if a matched file is found in their parent directory?
E.g. if I have the following tree:
./a/file.ok
./a/a1/
./a/a2/
./b/file.missing
./b/file.expect
./b/b1/
./b/b2/
./c/c1/
./c/c1/c11/
./c/c1/c11/foo.expect
./c/c1/c11/foo.txt
Then I would like to print only:
./a/file.ok
./b/file.missing
./b/file.expect
./c/c1/c11/foo.expect
without actually searching/traversing all the subdirectory trees of a/
and b/
(This earlier question approaches what I want, but hasn't yet really been answered.)