redirect find output


 
Thread Tools Search this Thread
# 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?
# 2  
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 10:27 AM..
# 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 04: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

This User Gave Thanks to Corona688 For This Post:
# 5  
It will have to come over all the directories anyway ... but ok, you saved grep pipeline ... Smilie

Last edited by ctsgnb; 03-22-2012 at 05:55 PM..
# 6  
Solaris 10, bash shell
# 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

 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #125
Difficulty: Easy
UNIX is a certification of a complete OS system, not only a UNIX kernel.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirect script output to a file and mail the output

Hi Guys, I want to redirect the output of 3 scripts to a file and then mail the output of those three scripts. I used below but it is not working: OFILE=/home/home1/report1 echo "report1 details" > $OFILE =/home/home1/1.sh > $OFILE echo... (7 Replies)
Discussion started by: Vivekit82
7 Replies

2. Shell Programming and Scripting

script to mail monitoring output if required or redirect output to log file

Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions. ... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

3. Shell Programming and Scripting

Redirect SFTP Output only

HI Guys, My requiement is to redirect output and error of sftp to a file.I have gone through few solutions given in this forum and got the alternate solution but not the one i want. Below piece of code is not working .. $ sftp user@server<<EOF 2>&1 >temp.txt > cd <dir> > ls > EOF... (0 Replies)
Discussion started by: mohanpadamata
0 Replies

4. Shell Programming and Scripting

How to redirect output of ls to a file?

Hi All, I want to redirect only the file names to a new file from the ls -ltr directroy. how Can i do it. my ls -ltr output will be as below. -rwxr-xr-x 1 118 103 28295 Jul 26 2006 event.podl -rwxr-xr-x 1 118 103 28295 Jul 26 2006 xyz.podl I want my new file... (6 Replies)
Discussion started by: girish.raos
6 Replies

5. Shell Programming and Scripting

output redirect

Hi i am compiling a source code by make command. i want to redirect the output of make to a file but at the same time i want to see the output in terminal. how to do this ?. please suggest your idea. thanks in advance. Saravana ---------- Post updated at 05:24 PM ----------... (2 Replies)
Discussion started by: tsaravanan
2 Replies

6. Shell Programming and Scripting

Redirect Output

Hi, I would like to list files: ls *.hdf But I would like a copy of the output directed to the screen, but also APPENDED to a text file: test.txt I have tried: ls *.hdf | tee test.txt However, that will just write over everything already existing in test.txt. How can I append the... (1 Reply)
Discussion started by: msb65
1 Replies

7. Shell Programming and Scripting

Hi How to redirect the output of exec

Hi Here i have a script a #!/usr/bin/env tclsh puts "Hello World!" set filename "./BesRun.sh" > out.txt exit I am trying to redirect the output of the "./BesRun.sh" to out.txt,but it is not happening can anyone let me know (2 Replies)
Discussion started by: nathgopi214
2 Replies

8. Shell Programming and Scripting

Redirect output

Hi all, I have a script which call a java program, the logging (to log file) in the program is done using log4j. However, as a safety measure, i still choose to direct standard error to another log file as follow /usr/bin/java -classpath ${classpath} -Xmx128m TestingProgram 2>>... (1 Reply)
Discussion started by: mpang_
1 Replies

9. UNIX for Dummies Questions & Answers

Redirect output to a file

Ahhhrrrggg I’m having a brain fart… I want to take the output of a command and redirect it to a file… This works…. $ man cp | cat >> copy_help but this doesn’t keytool -help |cat >> keytool_help It just produces… these lines… more keytool_help ] ... ]... (11 Replies)
Discussion started by: jimmyc
11 Replies

10. UNIX for Dummies Questions & Answers

Redirect time output

Hello All, I am trying to write a script that would capture the output of time command on a Sun machine. I have tried these commands $ time ls > out $ time ls 2> out I just get the ls output in the out file for the first one. Thanks for any help Chuck (2 Replies)
Discussion started by: cbeech
2 Replies

Featured Tech Videos