fbpx Linux tee Command: Save Output to File & Show on Terminal | Certificação Linux

Linux tee Command: Save Output to File and Display on Terminal

📅 01/01/2019 ⏱ 2 min ✍️ Uira Ribeiro
Linuxcommands
Linux tee Command: Save Output to File and Display on Terminal
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

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

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp