LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   find /common -name lost+found -prune -or -name fileTofind -print (http://www.linuxquestions.org/questions/linux-general-1/find-common-name-lost-found-prune-or-name-filetofind-print-4175435214/)

kaz2100 11-02-2012 03:10 AM

find /common -name lost+found -prune -or -name fileTofind -print
 
Hya,

Question
Why do these two commands return different result?
Code:

>find /common -name lost+found -prune -or -name fileToFind
/common/lost+found
/common/fileTofind
>

and
Code:

>find /common -name lost+found -prune -or -name fileToFind -print
/common/fileTofind
>

man page reads (man find)
Quote:

If the expression contains no actions other than -prune, -print is performed on all files for which the expression is true.
My system
Debian wheezy, AMD64 current. Version of find is 4.4.2. The directory /common is nfs mounted. Filesystem is EXT3.


My guess
My guess, (obviously incorrect) was that "-print" would be performed regardless of its existance at the end of command line. (commands after -or)

Closing remark
Thank you for your reading my post. Have a nice day!

cheers

SecretCode 11-03-2012 09:24 AM

I see the same results.

Here's what I think is going on:
Code:

find /common -name lost+found -prune -or -name fileToFind
is parsed as (with implicit print included):
Code:

find /common ( ( -name lost+found -prune ) -or ( -name fileToFind ) ) -print
But
Code:

find /common -name lost+found -prune -or -name fileToFind -print
is parsed as
Code:

find /common ( ( -name lost+found -prune ) -or ( -name fileToFind -print ) )
-prune returns true, but in the second syntax the -print action doesn't see it.

See the section in man find ending
Code:

                                        The expression on the right hand side of the -o is in parentheses only for clarity.  It
      emphasises that the -print0 action takes place only for things that didn't have -prune  applied  to  them.  Because  the
      default `and' condition between tests binds more tightly than -o, this is the default anyway, but the parentheses help to
      show what is going on.


kaz2100 11-05-2012 04:36 AM

My bad!

After reading the post #2, I am depressed!!


All times are GMT -5. The time now is 04:52 AM.