redirect find output


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers redirect find output
# 1  
Old 03-22-2012
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  
Old 03-22-2012
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 09:27 AM..
# 3  
Old 03-22-2012
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 03:44 PM..
# 4  
Old 03-22-2012
-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  
Old 03-22-2012
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 04:55 PM..
# 6  
Old 03-22-2012
Solaris 10, bash shell
# 7  
Old 03-23-2012
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

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How do I redirect output from "find", either to a file or another command?

I'm trying to find out what happened to the rogue game that apt-get told me it installed, so I thought I would find the file. I went to the root and entered: find -name "rog*.*" I get a large number of lines saying my access is denied in various directories. I figure I'll practice my Unix... (14 Replies)
Discussion started by: arghvark
14 Replies

2. Shell Programming and Scripting

Redirect output from terminal

i make a shell script. There has a line wget https://cisofy.com/files/lynis-2.1.0-88394c1affb9e23bd7390098947b3fd4b04e35e8.tar.gzWhen this line execute terminal show some text like this Resolving cisofy.com (cisofy.com)... 149.*.*.* Connecting to cisofy.com (cisofy.com)|149.*.*.*|:4444...... (4 Replies)
Discussion started by: Devils-ey3
4 Replies

3. 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

4. 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

5. AIX

Not able to redirect output of command

Hi All,. We are using AIX as the OS to host the Oracle ERP. We have a command FNDLOAD which is used to load setups. When this command is run, it outputs names of log files and any errors to the screen. I am trying to redirect this output to a file because we have large number of these... (4 Replies)
Discussion started by: mansmaan
4 Replies

6. UNIX for Dummies Questions & Answers

p7zip redirect output

Hi evreybody In my program i work with file compressed with 7zip I need to decompress these file I've red the man page of p7zip which is very short (maybe too short) Is there another program to work whit 7zip files I need options like redirect output (p7zip decompress file in the... (1 Reply)
Discussion started by: the_bouk
1 Replies

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question