bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: find traverses through directory while it's excluded


From: Dale R. Worley
Subject: Re: find traverses through directory while it's excluded
Date: Fri, 12 Feb 2016 10:57:34 -0500

"PenguinWhispererThe ." <address@hidden> writes:
> So while someone might think -not -iwholename excludes that directory that
> is looping it will still traverse it.
> Why is find still traversing if a directory is excluded?
> Is this for corner-cases? Can someone give an example of those?
>
> I understand there is the -prune option for this. I'm just trying to
> understand why(and there might be a very good reason) :)

I think you understand the point, actually:  The find expression, in
general, determines what entries will be printed out, but it does not
limit what directories will be traversed.

Really, it has to be that way to do what people normally want.  If I
write

    find . -name abc

I want it to find ./def/abc.  So find has to descend into ./def, even
though its name does not match 'abc'.

Based on this, I can explain what '-prune' does:  It's a predicate, and
it always returns true.  But it has a side-effect, which is to stop find
from traversing the entries in the current directory.

The result is a common idiom:  If you want to avoid descending into
'excludedir', write:

    find -L /src/tree/ -iwholename *excludedir* -prune -false -o ...

The first clause of the OR only acts on 'excludedir', and its effect is
to prevent find from traversing it (-prune) and also to prevent it from
being printed (-false):  If the -iwholename returns true, then find
tests -prune.  -prune returns true, so find tests -false.  That's false,
so find goes to the other OR clause.

(You write whatever criteria you want for printing entries in place of
"...".)

Dale



reply via email to

[Prev in Thread] Current Thread [Next in Thread]