Problem with find -prune...

Mike Meyer mwm-keyword-freebsdhackers2.e313df at
Sun Mar 23 22:18:06 PDT 2008

find -prune seems to not quite do what it says. At least, when delete
is used. Here's an example tree (on 7.0-RELEASE, amd64 build):

bhuda# ls -Rl /tmp/x
total 2
drwx------  2 root  wheel  512 Mar 24 01:01 y

total 2
-rw-r--r--  1 root  wheel  1111 Mar 24 01:01 motd

/tmp/x contains a subdirectory closed to everyone but root, which has
a file in it. No problem. Point find at it as a user:

bhuda% find /tmp/x -print
find: /tmp/x/y: Permission denied

As expected, it complains. Now let's use prune to trim the search - at
the root of the tree:

bhuda% find /tmp/x -prune

Hmm, it prints the root of the tree. That might be a bug; might
not. But we can fix it with a little tweak:

bhuda% find /tmp/x -prune -o -print

Making the print conditional on not pruning, and we always prune. Ok,
now let's look at what looks to me like a bug:

bhuda% find /tmp/x -prune -o -delete
find: /tmp/x/y: Permission denied

Why on earth (or off it) is find trying to look at /tmp/x? Am I
correct in assuming that this is a bug?

Mike Meyer <mwm at>
Independent Network/Unix/Perforce consultant, email for more information.

More information about the freebsd-hackers mailing list