Linux Commands - tee (redirect output to both the console and a file)

by
Jeremy Canfield |
Updated: March 09 2020
| Linux Commands articles
The tee command can be used to both redirect text to a file and to also display the text in the Terminal. In this example, the text Hello World is both redirected to example.txt and is also displayed in the Terminal.
~]# echo "Hello World" | tee example.txt
Hello World
The cat command can be used to ensure that the text Hello World was redirected to example.txt.
~]# cat example.file
Hello World
Append
By default, the tee command without any options will overwrite the target file. The -a or --append option can be used to append text to the target file. In this example, the text How are you today is appended to example.txt.
~]# echo "How are you today" | tee -a example.txt
How are you today
The cat command can be used to ensure that the text How are you today was appended to example.file.
~]# cat example.txt
Hello World
How are you today
Did you find this article helpful?
If so, consider buying me a coffee over at