Now what would you expect this to print out?

Jonathan Chen jonc at chen.org.nz
Mon May 19 10:02:11 UTC 2008


On Mon, May 19, 2008 at 01:49:35AM -0700, Garrett Cooper wrote:
> Riddle for the day for folks that have source trees... what would you expect
> this to print out (ask yourself the question and then execute the command)?
> 
>      find /usr/src -name Makefile -or -name '*.mk' -print
> 
> The expected output and what actual output differed in my mind, but maybe
> somebody else can "shed some light" on the logic behind what happened

It's a problem that catches many young players with find(1). One has
to remember from reading the man-page that all directives have an
implicit AND operator on it; and that includes the "-print" directive.
So to get what you want, you have to introduce brackets:

    find /usr/src \( -name Makefile -or -name '*.mk' \) -print

Cheers.
-- 
Jonathan Chen <jonc at chen.org.nz>
----------------------------------------------------------------------
  If you're right 90% of the time, why quibble about the remaining 3%?


More information about the freebsd-questions mailing list