bug-findutils
[Top][All Lists]
Advanced

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

Re: Technical reason to use `-path "./foo" -prune` vs `-name "foo" -prun


From: James Youngman
Subject: Re: Technical reason to use `-path "./foo" -prune` vs `-name "foo" -prune`
Date: Tue, 5 Apr 2011 10:21:49 +0100

On Tue, Apr 5, 2011 at 1:23 AM, Peggy Russell
<address@hidden> wrote:
>> > 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

The -name and -path tests really really aren't interchangeable,
whether you are using -prune or not.   The fact that they give the
same result in your tests is because the data (i.e. filesystem
content) you appear to be working on here does not include any of the
cases which would demonstrate the difference (for example,
./baz/umsp/foo/name.txt: the first command would visit it, and the
second would not).

James.



reply via email to

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