Sometimes it’s convenient to direct the output of a command to both the screen and a file. Here’s how to do it:
command 2>&1 | tee output.log
tee command copies
stdout, and makes a copy of the input to a file. The
2>&1 part also directs the
stderr output, in addition to
stdout. You can use
tee -a to append to the log instead of overwriting.