In bash, calling foo
would display any output from that command on the stdout.
Calling foo > output
would redirect any output from that command to the file specified (in this case 'output').
Is there a way to redirect output to a file and have it display on stdout?
Best Answer
The command you want is named
tee
:For example, if you only care about stdout:
If you want to include stderr, do:
2>&1
redirects channel 2 (stderr/standard error) into channel 1 (stdout/standard output), such that both is written as stdout. It is also directed to the given output file as of thetee
command.Furthermore, if you want to append to the log file, use
tee -a
as: