Some nice tee
April 02, 2014
I wanted to log something in bash to the console and to a log file.
Turns out there’s a command for that
tee
more information here
So a very simple example would be
ls | tee test.txt
which will display the output of ls to the screen and store the result in the file test.txt.
By default it overwrites the file, if you want an ongoing log use the -a option
ls | tee -a test.txt
If you want errors as well, also useful for a log file, redirect stderr to stdout
ls -e 2>&1 | tee -a text.txt
The test.txt file will contain the error about -e being an invalid option
Written by David Kerwick who lives and works Dublin as a Java Technical Lead.