Skip to content

Tee command on Linux (writes data to file and standard output)

The tee command in Linux receives data from a standard input, writes what it received in a file, and then sends it to its standard output. It is used to save the standard output of a command to a file and also send this output to another command.

It solves the problem of sending output from one program to one file and at the same time to another program.

The option is:

  • -a: Add what was received at the end of the file instead of writing on top.

Example:

$ payroll | tee folha.txt | print_bill | tee boleto.txt | lpr 2> erros.log

The result of the payroll program is recorded by the tee in the folha.txt file and sent to the imprime_bill program. In turn, the Imprime_Boleto program redirects your output to second tee that records the result in the boleto.txt file, which is also sent to the lpr program that prints the tickets. If the printing error occurs, this error is written to the erros.log file.

Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it?

Share