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

xyz 2>&1 | tee logfile

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

xyz |& tee logfile

Comments are closed.