LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   redirecting output to multiple outputs (https://www.linuxquestions.org/questions/linux-general-1/redirecting-output-to-multiple-outputs-145273/)

granny 02-12-2004 11:17 AM

redirecting output to multiple outputs
 
I want to redirect output to multiple places, how can this be done. Something simple as...

ls /etc redirected to both a file and monitor. I know how to redirect to a file and understand std output is monitor, but how do I do both in 1 command?

ls /etc > file and then???

Oliv' 02-12-2004 12:01 PM

Code:

ls /etc/ 2>&1 | tee file
Hope this help you ;)

granny 02-12-2004 12:04 PM

sweet, thanks oliv, worked perfectly. What did the 2>&1 do though

Oliv' 02-12-2004 12:11 PM

If my memory is good: 2>&1 is used to duplicate stderr to stdout

granny 02-12-2004 01:56 PM

that's what I though, but ls /etc isn't an err so why does it work. Wouldn't it just produce stnd out? Either way thanks Oliv!

Oliv' 02-13-2004 06:27 AM

It works because stdout remains stdout... You just add messages from stderr to stdout.
It's just a precaution if you process commands which can cause errors

hiteshmaisheri 02-13-2004 07:18 AM

the 2>&1 means that both stdout and sterr to the pipe and then to the tee command and to the file


All times are GMT -5. The time now is 12:13 AM.