cancel
Showing results for 
Search instead for 
Did you mean: 

Re: find command

 
SOLVED
Go to solution
Super Advisor

find command

 

The cmd:

 

find / -exec ls -l {} \;

 

will provide the output I'm looking for, but if I want to send output to screen AND a file OR just to a file, what would that syntax be?

 

Thx in advance...

 

 

2 REPLIES 2
Acclaimed Contributor
Solution

Re: find command


@john guardian wrote:

 

find / -exec ls -l {} \;

 

will provide the output I'm looking for, but if I want to send output to screen AND a file OR just to a file, what would that syntax be?

 


Hi:

 

Use 'tee' to send the ouput to your terminal and a file:

 

# find / -exec ls -ld {} + | tee /var/tmp/myoutput

 

Notice that I also changed your 'ls -l' to 'ls -ld'.  THis is because you will do an 'ls -l' on *both* files and directories otherwise leading to duplicated output.

 

Notice too that the '\;' terminator for '-exec' means that you spawn one process for every argument!   This will really drag your perfomance down.  Using '{} +' causes mutiple arguments to be assembled for every process instantiation.  This is akin to using 'xargs' and greatly improves performance!

 

Regards!

 

...JRF...

Acclaimed Contributor

Re: find command (redirection)

>if I want to send output to screen AND a file OR just to a file, what would that syntax be?

 

Why?  You just redirect the output to a file and put the find(1) in the background and do something else.  If you are thinking about using tee(1), don't.

find / -exec ls -ld {} + > find-output 2>&1

 

Then you can use "tail -f" or other commands while it is working.

 

>This is akin to using 'xargs' and greatly improves performance!

 

It is orders of magnitude better than xargs(1), assuming large start up costs as with ll(1).