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

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter ec9c4b in the box below so that we can be sure you are a human.