Log output to both console and file with tee

Tee is a handy command to use if you want to get the output of a command or program to both console and to a log file. By redirecting stderr to stdout with 2>&1 you are sure to log both streams

Example: stderr is redirected to stdout and stdout is piped to tee which writes both to the console and to logfile

[simterm]
$ xyz 2>&1 | tee logfile
[/simterm]

In bash you can use |& as shorthand for 2>&1 |. Example:

[simterm]
$ xyz |& tee logfile
[/simterm]

Comments are closed.