bug-findutils
[Top][All Lists]
Advanced

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

Re: -iname a -or -iname b -exec: not on all files


From: James Youngman
Subject: Re: -iname a -or -iname b -exec: not on all files
Date: Sun, 14 Sep 2008 16:21:33 +0100

On Sun, Sep 14, 2008 at 3:45 PM, Carles Pina i Estany <address@hidden> wrote:
>
> Hello,
>
> I don't know if I've found an "unexpected feature", a bug in find, in
> the manual or in me:
>
> If I execute (for example in /usr/share/doc, in a Debian system with
> find from findutils 4.4.0):
>
> find . -type f -iname "*copy*" -or -iname "*changelog*" | wc -l
> Result: 4619
>
> If I execute:
> find . -type f -iname "*copy*" -or -iname "*changelog*" -exec echo {}
> \;|wc -l
> Result: 2841

Yup, because this is equivalent to

find . -type f -iname "*copy*" -or \( -iname "*changelog*" -exec echo {} \)

... since the (implicit) and operator has higher precedence than -or.
 See "OPERATORS" in the manual page - or if you are reading the
Texinfo manual, "Combining Primaries With Operators".

>
> Visually checking I can see that echo {} is executed only for
> *changelog* files, not for *copy* files.
>
> I can get what I wanted executing:
>
> find . -type f -iname "*copy*" -exec echo {} \; -or -iname "*changelog*"
> -exec echo {} \; | wc -l
> Result: 4619
>
> (of course, I was not executing echo {} for each file, this is just a
> test case)

Yes, it also has needless repetition.   You would probably find it
easier to use parentheses (but since these are also special to many
shells they will probably need to be escaped).

>
> Is this a bug in the manual? In find? In me? :-)
> If it's in find looks a bit important...
>
> Thanks and sorry for the noise, specially if this is not a bug.
>




reply via email to

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