The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to find a file named vijay in a directory using find command amirthraj_12 UNIX for Dummies Questions & Answers 6 3 Weeks Ago 09:37 AM
Can I know find syntax to find given date files bache_gowda Shell Programming and Scripting 3 03-26-2008 03:37 AM
Little bit weired : Find files in UNIX w/o using find or where command jatin.jain Shell Programming and Scripting 10 09-19-2007 03:47 AM
Find files older than 20 days & not use find halo98 Shell Programming and Scripting 2 05-18-2006 11:19 AM
command find returned bash: /usr/bin/find: Argument list too long yacsil Shell Programming and Scripting 1 12-15-2003 03:38 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 04-23-2008
Registered User
 

Join Date: Apr 2008
Posts: 25
Find help

i am trying to write ideally a one liner that will find all of the folders inside of a volume that don't contain a subfolder starting with the letter e and at the same time do contain a subfolder named 'images' that are not empty.

so far i have this
find /Volumes/image/ \! \( -name "e*" -and /images -empty

up to this point

find /Volumes/image/ \! \( -name "e*"

minus the ( of course i am pretty sure that it works to find directories inside of /Volumes/image/ that don't have subdirectories starting with e.


Again the desired output is.
Volumes/image/*/(no dirs starting with e) and at the same time /Volumes/image/*/images/(anything just not empty). Thats what i am trying to get.

Any help will be appreciated.

Thanks,
Movomito

Last edited by Movomito; 04-23-2008 at 07:09 AM.
Reply With Quote
Forum Sponsor
  #2  
Old 04-23-2008
rubin's Avatar
Registered User
 

Join Date: Nov 2007
Posts: 215
Quote:
Originally Posted by Movomito View Post

Again the desired output is.
Volumes/image/*/(no dirs starting with e) and at the same time /Volumes/image/*/images/(anything just not empty). Thats what i am trying to get.

Any help will be appreciated.

Tested with GNU find:

Code:
find /Volumes/image/ -type d    \!  \(  -name "image*" -empty \)  \! -name "e*"

Last edited by rubin; 04-23-2008 at 08:01 AM. Reason: replaced . with /Volumes/image/
Reply With Quote
  #3  
Old 04-23-2008
Registered User
 

Join Date: Apr 2008
Posts: 25
find /Volumes/image/ -type d \! \( -name "image*" -empty \) \! -name "e*"

this works great. Thank you. However, my output is a list of all of the directories and sub directories. Ideally i would get output that is a list of directories where this is true

so rather than this:

/Volumes/image/W00EGS1012593
/Volumes/image/W00EGS1012593/images
/Volumes/image/W00EGS1012593/images/W00EGS1012593-I00EGS1017114
/Volumes/image/W00EGS1016181
/Volumes/image/W00EGS1016181/images
/Volumes/image/W00EGS1016181/images/W00EGS1016181-I1PD10388
/Volumes/image/W00EGS1016199
/Volumes/image/W00EGS1016199/images
/Volumes/image/W00EGS1016199/images/W00EGS1016199-I00EGS1016201

i would just get:

/Volumes/image/W00EGS1012593
/Volumes/image/W00EGS1016181
/Volumes/image/W00EGS1016199

or even better:

/W00EGS1012593
/W00EGS1016181
/W00EGS1016199

thank you. Any help is appreciated
Reply With Quote
  #4  
Old 04-23-2008
rubin's Avatar
Registered User
 

Join Date: Nov 2007
Posts: 215
Quote:
Originally Posted by Movomito View Post
find /Volumes/image/ -type d \! \( -name "image*" -empty \) \! -name "e*"

this works great. Thank you. However, my output is a list of all of the directories and sub directories. Ideally i would get output that is a list of directories where this is true
...
or even better:

/W00EGS1012593
/W00EGS1016181
/W00EGS1016199

thank you. Any help is appreciated
If your find supports maxdepth then use the following code. Run it from current dir ( ie. /Volumes/image/ ) :

Code:
find . -maxdepth 1 -type d    \!  \(  -name "image*" -empty \)  \! -name "e*"
Reply With Quote
  #5  
Old 04-23-2008
Registered User
 

Join Date: Apr 2008
Posts: 25
the -maxdepth took care of cleaning up my output.

However, now i have noticed that the \! -name "e*" doesn't seem to be working.

While it is not outputting directories that start with e it is outputting directories that have subdirectories in them that start with e.

For example

./W00EGS1016928
./W00EGS1016928/images
./W00EGS1016928/images/W00EGS1016928-I01JW231

and ./W00EGS1016928/ebook/ does exist

almost there though

Thanks
Reply With Quote
  #6  
Old 04-23-2008
rubin's Avatar
Registered User
 

Join Date: Nov 2007
Posts: 215
Using maxdepth find will not search in the subdirectories anymore, so back to the initial working code, by modifying it a little, you'd get the output described in your second post:

Quote:
Originally Posted by Movomito View Post
....
so rather than this:

/Volumes/image/W00EGS1012593
/Volumes/image/W00EGS1012593/images
/Volumes/image/W00EGS1012593/images/W00EGS1012593-I00EGS1017114
/Volumes/image/W00EGS1016181
/Volumes/image/W00EGS1016181/images
/Volumes/image/W00EGS1016181/images/W00EGS1016181-I1PD10388
/Volumes/image/W00EGS1016199
/Volumes/image/W00EGS1016199/images
/Volumes/image/W00EGS1016199/images/W00EGS1016199-I00EGS1016201

i would just get:
...
or even better:

/W00EGS1012593
/W00EGS1016181
/W00EGS1016199

...
Running it again from the current directory:

Code:
find . -type d    \!  \( -name "image*" -empty \)  \! -name "e*" | awk -F'/' '{a[$2]++; if ( a[$2]==1 ) print "/"$2}'
Hope this helps.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0