LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 07-29-2022, 11:06 AM   #1
Jrubiando
LQ Newbie
 
Registered: Jul 2022
Posts: 2

Rep: Reputation: 0
find command has prob with directory


This find command somehow complains about a directory when I would have thought that '-type f' would have taken care of it. Without all the prune and everything else it seems to be ok. I'm actually doing this on a Mac but Macs seem to have most of the same stuff that linux does for this type of thing

% find . -type f ! \( -name "*.vue" -or -name "*.slim" -or -name "*.js" -or -name "*.erb" \) -o -path './vendor' -prune -o -path './public' -prune -o -path './spec' -prune -o -path './node_modules' -prune -o -path './config' -prune -exec egrep 'extra_fields' {} \; -print

egrep: ./config: Is a directory

Last edited by Jrubiando; 07-29-2022 at 11:08 AM.
 
Old 07-29-2022, 12:55 PM   #2
Jrubiando
LQ Newbie
 
Registered: Jul 2022
Posts: 2

Original Poster
Rep: Reputation: 0
This seems to work

find . -type f -not -path './vendor/*' -not -path './config/*' -not -path './public/*' -not -path './spec/*' -not -path './node_modules/*' \( -name "*.js" -or -name "*.slim" -or -name "*.vue" -or -name "*.erb" \) -exec egrep "extra_field|ExtraField" {} \; -print
 
Old 07-29-2022, 01:22 PM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Directories are type f also. This is why you see that. There are probably options for the command to suppress errors.
 
Old 07-29-2022, 02:02 PM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,783

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
Quote:
Originally Posted by rtmistler View Post
Directories are type f also. This is why you see that. There are probably options for the command to suppress errors.
Excuse me, but "-type f" in the find command specifically matches "ordinary files".

To the OP, the problem with your original expression is operator precedence and binding, and also a misunderstanding of the "-prune" action.
Quote:
Originally Posted by Jrubiando View Post
Code:
% find . -type f ! \( -name "*.vue" -or -name "*.slim" -or -name "*.js" -or -name "*.erb" \)  -o  -path './vendor' -prune -o -path './public' -prune -o -path './spec' -prune -o -path './node_modules' -prune -o -path './config' -prune -exec egrep 'extra_fields' {} \; -print
The operands of find that follow the search path operands form a Boolean expression evaluated according to precedence and binding rules. Your "-type f" is AND-ed only with the immediately following negated parenthesized term, and does not affect any of the OR-ed terms that follow. Also, the "-exec egrep ..." action term is bound only to the immediately preceding "-path './config' -prune" term, and will not be executed for anything else. And finally, matching a "-prune" test does prevent descending into that directory, but does not block the directory name itself.

Since the only actions in your expression are the final "-exec egrep 'extra_fields' {} \; -print" terms, and those are bound only to the "-path './config' -prune" term, the rest of the expression is effectively ignored and you are left with just
Code:
find . -path './config' -prune -exec egrep 'extra_fields' {} \; -print
which is far from what you intended.

Last edited by rknichols; 07-29-2022 at 02:03 PM.
 
Old 07-30-2022, 06:29 AM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,819

Rep: Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211
Have the -prune branch first, and continue with -o (OR, otherwise, if not pruned).
Code:
find . \( -path './vendor' -o -path './public' -o -path './spec' -o -path './node_modules' -o -path './config' \) -prune -o -type f ! \( -name "*.vue" -o -name "*.slim" -o -name "*.js" -o -name "*.erb" \) -print -exec egrep 'extra_fields' {} \;
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find directory older than x and mv directory with sub files command ajhart Linux - Newbie 4 07-15-2011 05:24 AM
Subtitle prob + Keyboard/Mouse Prob 2Pacalypse Ubuntu 1 02-26-2007 02:49 PM
red hat 9, printer prob and connection prob lasttriptotulsa Linux - Newbie 4 01-17-2007 03:39 AM
XFree keyboard problem, Quake prob and half-life prob cradlebin Linux - Software 0 09-21-2003 06:57 AM
Man 9.0 printer ? hardware prob ? install prob romcgill Linux - Hardware 2 02-24-2003 04:54 AM

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

All times are GMT -5. The time now is 07:48 PM.

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