The -prune
option does not seem to work for me this way on MacOS Monterey (12.01):
find ~/Documents -path "~/Documents/_learning/*" -prune -o -type f -print
It does not exclude the files in ~/Documents/_learning
directory.
What am I doing wrong? (The command was constructed using e.g. this answer, as well as several others.)
Here is hopefully a reproducible experiment. (You can pick any two nested directories available to you with one or more files in them and do a similar experiment.) Counting the files in ~/Documents
:
find ~/Documents -type f -print | wc -l
428
find ~/Documents/_learning -type f -print | wc -l
279
... then excluding the ~/Documents/_learning
directory should produce 149 files - yet:
find ~/Documents -path "~/Documents/_learning/*" -prune -o -type f -print | wc -l
428
... i.e. the same number as without the exclusion. Using the full path (/Users/<userID>/Documents/...
) - does work. Using a relative path with ./Documents/...
- does not. How I know:
find ~/Documents -type f | grep -v "/Documents/_learning/" | wc -l
149
Which brings me to: what am I doing wrong? Why does only the full path work?
Thank you!
P.S. -not -path ...
- same behavior;
find ~/Documents -not -path "~/Documents/_learning/*" -type f -print | wc -l
428
find ~/Documents -type f -not -path "~/Documents/_learning/*" | wc -l
428
find ~/Documents -type f -not -path ~/Documents/_learning/ | wc -l
428
Yet it does work with a full path:
find ~/Documents -type f -not -path "/Users/<userID>/Documents/_learning/*" | wc -l
149