LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-29-2014, 07:32 PM   #1
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Rep: Reputation: 40
linux find command fail with four '-name'


Hi group.
I found an interesting problem using the find command. If I use '-or -name' with than 3 '-name' options the command fails. Here is the output of a three parm and 4 parm example.
Quote:
find ../.. -name '*.log' -or -name 'core.*' -or -name '*~' -exec ls -l {} \;
-rwxr-xr-x. 1 wre00 root 107 Dec 26 2011 ../../Makefile.am~
-rw-r--r--. 1 wre00 root 21077 Oct 29 15:25 ../../Makefile~
find ../.. -name '*.log' -or -name 'core.*' -or -name '*~' -or -name '*.dat' -exec ls -l {} \;
I am running Fedora 13. Care to comment?
 
Old 10-29-2014, 07:46 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by MrUmunhum View Post
Code:
find ../.. -name '*.log' -or -name 'core.*' -or -name '*~' -exec ls -l {} \;
Please use [CODE]...[/CODE] tags and not [QUOTE] tags for code. Material that is already a quote will not be automatically quoted in a followup.

The way you have it written, the "-exec" action is bound only to the last "-name" test, i.e., the implied parentheses are:
Code:
find ../.. -name '*.log' -or -name 'core.*' -or \( -name '*~' -exec ls -l {} \; \)
You need explicit parentheses around the set of "-name" tests:
Code:
find ../.. \( -name '*.log' -or -name 'core.*' -or -name '*~' \) -exec ls -l {} \;
 
Old 10-29-2014, 07:48 PM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
What rnichols said...
 
Old 11-02-2014, 04:45 PM   #4
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by rknichols View Post
Please use [CODE]...[/CODE] tags and not [QUOTE] tags for code. Material that is already a quote will not be automatically quoted in a followup.
Fair enough, my fault.
Quote:
Originally Posted by rknichols View Post
The way you have it written, the "-exec" action is bound only to the last "-name" test, i.e., the implied parentheses are:
Code:
find ../.. -name '*.log' -or -name 'core.*' -or \( -name '*~' -exec ls -l {} \; \)
You need explicit parentheses around the set of "-name" tests:
Code:
find ../.. \( -name '*.log' -or -name 'core.*' -or -name '*~' \) -exec ls -l {} \;
Now for the discussion. Your explanation make sense. Explicitly binding the last '-name' with the '-exec' sounds right, but that means the previous '-name' options are no-ops? Should that have caused an error message?

In the future I must remember to use parentheses.

Thanks for you input and time. I will makr this as solved.
 
Old 11-02-2014, 05:59 PM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
[QUOTE=MrUmunhum;5263517]
Quote:
Originally Posted by rknichols View Post
but that means the previous '-name' options are no-ops? Should that have caused an error message?
All of those "options" are just elements in a boolean expression which can be quite complex. In cases like yours, it's easy to see that those terms could never cause evaluation of any action element, but in general that is not easy to determine. For the case where there is no action element at all, find does use a default action of "-print" if the overall expression evaluates to true, but if there is any action, find just evaluates the expression you supplied, and if that does not involve any action, so be it.

FWIW, the C compiler too does not require that a conditional expression result in any action that has side effects. The following is valid C and compiles without warnings, even with "-Wall" as long as variable x is defined and set. In fact, the pointless test gets optimized out entirely.
Code:
if(x == 5) { }
Quote:
In the future I must remember to use parentheses.
We've all made that same mistake. In fact, I made it myself about an hour after posting my reply.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find the core files in linux with out using "Find" command? shaktiman Linux - Newbie 11 08-02-2010 09:46 AM
How to find the core files in linux with out using "Find" command? shaktiman Programming 1 07-30-2010 10:31 AM
Bug in slackpkg -- fail to find installed package? grissiom Slackware 8 07-16-2009 05:26 AM
F7 install fail - unable to find device drivers idk666 Linux - General 0 10-01-2007 02:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10: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