On 2019-10-03 00:10, Peng Yu wrote: > I’ve checked this many years ago. One directory exec is not acceptable in > my case. I ended up with two pass, one to check which directory to include > and exclude, then search for files in the directory included. But I am > looking for something better.
The problem with a test like "-name 'file.txt'" is that find is already visiting() a directory level too deep for a subsequent action to be effective. For your special case, you could try to locally add a new '-child PATTERN' predicate which could check for the existence below the current entry. A subsequent -prune would then skip that directory. I'd consider your use-case not common enough to add such an option to GNU find, as the existing solution via "-exec test -f '{}/file.txt' \;" seems to be sufficient for most cases. Have a nice day, Bern