[Top][All Lists]

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

Re: Bug in find

From: James Youngman
Subject: Re: Bug in find
Date: Wed, 23 Feb 2005 09:27:02 +0000
User-agent: Mutt/1.3.28i

On Wed, Feb 23, 2005 at 03:58:21AM +0100, Mave wrote:
> Hello,
> i have a problem (it seems to be a bug) by using GNU find
> version 4.1.7 on a Debian 3 Woody with Pinning (Unstable/Testing)

Please note that the current stable release of findutils is 4.2.18.

> I want to find files named *.cfg or *.ini. The documentation
> (man find) shows me to use the syntax below
>      find . -name '*.cfg' -or -name '*.ini'
> this works fine and without any problems. Now i want to use the -exec
> syntax to work with the files. I changed the command to
>      find . -name '*.cfg' -or -name '*.ini' -exec echo {} \;
> After i do that, the find only shows me the files ending with *.ini.
> The files named *.cfg where not displayed.

Yes, this is a consequence of the relative precedence of "-o" with
respect to the "implicit and".  See the findutils documentation
(section "Combining Primaries with Operators" in the Texinfo manual or
the section titled OPERATORS in the man page) for a table showing you
the relative precedence of the operators.

The reason the first command works as you expect is that when the
expressions given don't include -print or any other action with a side
effect, the -print action is taken for all files *for which the whole
expression is true* (see EXPRESSIONS in the man page).  Thus

  find paths expression 

is equivalent to 

  find paths ( expression ) -print

with appropriate shell quoting of course.

> I think its a Bug by using the -exec syntax in combination with the
> -or syntax.

> I hope you find the Bug and release an upgrade. I just going to write
> me a litte tool to get my work running.

No, it's not a bug.  You should use 

   find . \( -name '*.cfg' -or -name '*.ini' \) -exec echo {} \;

Hope the above helps,

reply via email to

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