Is there a way to have Bash redirect STDOUT/STDERR to a file yet still print them out to the terminal as well?
This will redirect both STDOUT and STDERR to the same file:
some_command 2>&1 | tee file.log
$ touch foo; ls foo asfdsafsadf 2>&1 | tee file.log
ls: asfdsafsadf: No such file or directory
foo
$ cat file.log
ls: asfdsafsadf: No such file or directory
foo
Use the tee command.
$ echo "hi" | tee output.txt
hi
[unix]$ ls
output.txt
[unix]$ cat output.txt
hi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With