Dual output to terminal screen and log file

If you need to see a command’s or one of your script’s standard error and output in a log file and on your terminal simultaneously, take a look at this command:


$ command 2>&1 | tee command.log;

What does the numbers mean the following command? Here is the explanation:

Name File Descriptor Description
stdin 0 standard input stream (e.g. keyboard)
stdout 1 standard output stream (e.g. monitor)
stderr 2 standard error output stream (usually also on monitor)

“2>&1” is telling us both standard error and standart output will be redirected together to standart output. After pipe, “tee” copies standard input to standard output or file.

References:

1-) http://stackoverflow.com/questions/13591374/command-output-redirect-to-file-and-terminal

2-) http://wiki.bash-hackers.org/syntax/redirection