|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
What Operating System and version do you have and what Shell are you using. Quote:
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
|
|||
|
|||
|
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
|
|||
|
|||
|
-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
|
|||
|
|||
|
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
|
|||
|
|||
|
Solaris 10, bash shell
|
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|