Linux tee Command: Save Output to File and Display on Terminal
The tee command in Linux receives data from standard input, writes what it received to a file, and also sends it to its standard output. It is used to write the standard output of a command to a file and also send this output to another command.
It solves the problem of sending the output of a program to a file and at the same time to another program.
The option is:
- -a: Appends what was received to the end of the file instead of overwriting.
Example:
$ folha_pagamento | tee folha.txt | imprime_boleto | tee boleto.txt | lpr 2> erros.log
The output of the folha_pagamento program is written by tee to the folha.txt file and sent to the imprime_boleto program. In turn, the imprime_boleto program redirects its output to the second tee which writes the result to the boleto.txt file which is also sent to the lpr program that prints the receipts. If there is a printing error, this error is written to the erros.log file.
Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.
Liked it? Share
That was just one piece. The course teaches the whole path — from your first command to exam day.