Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-22-2012
Registered User
 
Join Date: Mar 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
redirect find output

I'm trying to get a list of directories with "2012" as one of the sub-directories (ex. ./TRAN/U214OU/IN/2012/03/01). I tried using find like this "find . -name 2012 -type d > list.out" but it won't write to file. What am I doing wrong or is there a better way to do this?
Sponsored Links
    #2  
Old 03-22-2012
methyl methyl is offline Forum Staff  
Moderator
 
Join Date: Mar 2008
Posts: 6,388
Thanks: 286
Thanked 668 Times in 640 Posts
What Operating System and version do you have and what Shell are you using.

Quote:
find . -name 2012 -type d > list.out
Looks okay to me on virtually every modern version of unix/Linux in all Bourne-type shells.
Some older ones prefer:

Code:
find . -type d -name 2012 -print > list.out

Do you get an error message? If so, please post verbatim.

What is the output from these commands (while in the directory where you issued the command:

Code:
pwd
ls -lad list.out
cat list.out


Last edited by methyl; 03-23-2012 at 08:27 AM..
Sponsored Links
    #3  
Old 03-22-2012
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Location: France
Posts: 2,763
Thanks: 72
Thanked 587 Times in 561 Posts
You could then just list all your directory and grep for 2012 pattern


Code:
find . -type d | grep 2012

(Tested on my ubuntu, even if i look for -name "*2012*", if won't get ./2012/02/ or ./2012/02/ subdirectories since the 2012 is part of the dirname, and not pat of the name itself (which is just 02)

Since we don't know at which level in the parent name the 2012 will come, the simple find command mentionned above should bring the intended result ... as far as i understand the requirements.

Last edited by ctsgnb; 03-22-2012 at 02:44 PM..
    #4  
Old 03-22-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,407
Thanks: 492
Thanked 2,538 Times in 2,421 Posts
-name will match the name of the directory, not what directories its inside. -path will match against the path itself.


Code:
find . -path '*/2012/*' -type d

The Following User Says Thank You to Corona688 For This Useful Post:
ctsgnb (03-22-2012)
Sponsored Links
    #5  
Old 03-22-2012
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Location: France
Posts: 2,763
Thanks: 72
Thanked 587 Times in 561 Posts
It will have to come over all the directories anyway ... but ok, you saved grep pipeline ...

Last edited by ctsgnb; 03-22-2012 at 03:55 PM..
Sponsored Links
    #6  
Old 03-22-2012
Registered User
 
Join Date: Mar 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Solaris 10, bash shell
Sponsored Links
    #7  
Old 03-23-2012
methyl methyl is offline Forum Staff  
Moderator
 
Join Date: Mar 2008
Posts: 6,388
Thanks: 286
Thanked 668 Times in 640 Posts
Reference post #1. What does but it won't write to file mean? What actually happened?


Long shot. If there links in this directory tree, you might need:

Code:
find . -follow -type d -name 2012 -print > list.out

Please do post the output from:

Code:
pwd
ls -lad list.out
cat list.out

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
output redirect tsaravanan Shell Programming and Scripting 2 06-23-2009 07:33 AM
Redirect Output msb65 Shell Programming and Scripting 1 08-27-2008 10:02 PM
Redirect output mpang_ Shell Programming and Scripting 1 08-15-2007 08:57 AM
Redirect output to a file jimmyc UNIX for Dummies Questions & Answers 11 01-31-2007 10:34 AM
redirect output of FTP kcaluwae Shell Programming and Scripting 4 06-23-2005 08:45 AM



All times are GMT -4. The time now is 10:16 AM.