LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-02-2012, 03:10 AM   #1
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: SlackWare > Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy .. bullseye bookworm
Posts: 1,832

Rep: Reputation: 108Reputation: 108
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
 
Old 11-03-2012, 09:24 AM   #2
SecretCode
Member
 
Registered: Apr 2011
Location: UK
Distribution: Kubuntu 11.10
Posts: 562

Rep: Reputation: 102Reputation: 102
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.
 
Old 11-05-2012, 04:36 AM   #3
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: SlackWare > Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy .. bullseye bookworm
Posts: 1,832

Original Poster
Rep: Reputation: 108Reputation: 108
My bad!

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

Last edited by kaz2100; 11-05-2012 at 05:48 PM. Reason: typo
 
  


Reply

Tags
find, lost+found, nfs, prune



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] find with -prune and -delete sseeg Linux - General 8 01-10-2013 04:06 AM
[SOLVED] Using find and prune to not print path grail Linux - Newbie 2 01-10-2011 10:16 AM
Using find command with -prune and -xdev learn2bperfect Linux - Newbie 4 02-25-2009 11:22 PM
find using -prune and -size sharky Programming 4 09-24-2008 04:14 AM
How to prune a print & file server to leave minimal services running wolfpeach Linux - Security 4 06-29-2004 06:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration