LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Redirecting output to multiple locations? (https://www.linuxquestions.org/questions/linux-newbie-8/redirecting-output-to-multiple-locations-645533/)

SirTristan 05-29-2008 03:34 AM

Redirecting output to multiple locations?
 
How does one redirect the output for a command to multiple locations? For instance for:
Code:

ls /dir > out1.txt
Instead of just out1.txt, can one output to out1.txt and out2.txt?

And can one both output to an output file, and display the output to the shell screen as normal (as if there was no output redirection)?

ophirg 05-29-2008 03:58 AM

you can use
Code:

ls /dir > a ; cat a > b
it's a bit long, and technically it's a two commands
but it works

grizly 05-29-2008 04:02 AM

Quote:

$ls /dir | tee file1.txt | tee file2.txt
Enjoy dude, outputs to both files and displays on screen. ;)

Tinkster 05-29-2008 04:51 AM

And if you don't want to see it use tee and redirect ;}


Code:

$ls /dir | tee out1.txt > out2.txt

ophirg 05-29-2008 05:04 AM

Nice solution
Tinkster and grizly
didnt think about it...

colucix 05-29-2008 05:18 AM

Or simply
Code:

ls /dir | tee file1 file2 file3 file4 file5 ... fileN > /dev/null
;)

SirTristan 05-29-2008 03:52 PM

Quote:

Originally Posted by grizly (Post 3167906)
Enjoy dude, outputs to both files and displays on screen. ;)

Thanks, this works :)

The program that I actually want to output takes a very long time (hours), so the two commands option wouldn't work, but 'tee' does.


All times are GMT -5. The time now is 06:09 PM.