Archive for February 26th, 2007

Input/Output redirection

Posted in Linux SysAdmin on February 26th, 2007 by Johan Huysmans – 2 Comments

Everybody knows and uses output redirection to get the output of a command to a file.

With > you redirect STDOUT, with 2> you redirect STDERR and with &> you redirect both at the same time.

ls > output.txt
ls 2> error.txt
ls &> output_and_error.txt

But how do you get the output written to the screen AND to a file?

“tee” answers this question. This little program will accept text from STDIN and put in on STDOUT and write it to a file.
This is how you use it:

ls | tee output.txt