> > On a side note: I understand `-name` is the basename and `-path` is > > the dirname. Everything is a file. A directory can be matched > > with `-name` or `-path`, a file can only be matched with `-name` and > > `-path` if no slashes used. I almost always see `-name foo -prune` > > verses `-path ./foo -prune`. And was wondering if there was a > > technical reason? Is one more efficient than the other? > > They have different meanings. One will prune start/subdir/foo and > the other will not. >
In the examples below (one uses `-iname` (basename) and one uses `-path` (dirname relative to starting point)) pruned the directory '/foo'. I added `-D search` (that helps sometimes) and the output was the same for both. I know the man page mentions `-prune` under both `-name` and `-path`. `-path` also has a reference to POSIX. I doubled checked the POSIX `find` and `-path` was listed. http://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html It seems `-path` and `-name` are interchangeable as far as `-prune` goes, as long as the pattern is correct for each of them. find . -path "./foo" -prune -o -print ------------------------------------- . ./bar ./cc ./abc3.txt ./abc2.txt ./abc1.txt find . -name "foo" -prune -o -print ----------------------------------- . ./bar ./cc ./abc3.txt ./abc2.txt ./abc1.txt Data: find . -name "*" -printf '[%y] %-20p +%d \n' -------------------------------------------- [d] . +0 [d] ./bar +1 [f] ./cc +1 [f] ./abc3.txt +1 [d] ./foo +1 [f] ./foo/abc3.txt +2 [d] ./foo/baz +2 [f] ./foo/abc2.txt +2 [f] ./foo/abc1.txt +2 [f] ./abc2.txt +1 [f] ./abc1.txt +1 Thank you. Peggy Russell
