In this article we are going to show how to use tee command in Linux Terminal. If you want to learn about tee command in Linux with Examples then this post is ideal for you.
In the Linux computing, tee is a command line utility that is used to reads standard input and writes it to both standard output and one or more files. It is primarily used in combination with other commands with piping.
Linux is an operating system, like Windows OS, iOS, and Mac OS. Linux is one of the most popular operating system on the planet, Android is also powered by Linux OS(operating system). An operating system is software that manages all hardware resources associated with desktop or laptop. In simple words, the OS(operating system) manages communication between software and hardware.
Linux OS(operating system) is also distributed under an open source license. Open source following these points :
- Freely to run the program, for any purpose.
- Free to study how the program works.
- Freely to re-distribute copies so you can help your friends.
- Free to distribute copies of your modified versions to others.
Tee Command in Linux with Examples
tee Command Syntax
In the Linux, the basic syntax of the tee command is show as below:
tee [OPTIONS] [FILE]- Here, options are:
-a(--append) – It is used to append to the given file instead of overwrite the file.-i(--ignore-interrupts) – It is used to ignore interrupt signals.- Use tee
--help– it is used to view all available options.
- FILE – One or more files.
How to Use the tee Command
The tee command is used to print the standard output of a program and write the output in a file.
For an example:
$ df -h | tee outputfile.txtIn the above command, it will display the disk space details using df command and write(store) the output in the outputfile.txt file by piping with tee command.
Use cat command to check content of the outputfile.txt .
Write to Multiple File
$ command | tee filename1.txt filename2.txt filename3.txtAppend to File
Use the -a (--append) option to append the output to the given file.
$ command | tee -a filename.txtIgnore Interrupt
Use the -i (–ignore-interrupts) option to ignore interrupts. This option is useful when stopping the command during execution with the Ctrl+C and want to exit gracefully.
$ command | tee -i filename.txtHide the Output
$ command | tee file.txt >/dev/nullUsing tee in Conjunction with sudo
$ sudo echo "hello" > /etc/filename.confThe above command display a output something like below:
Output
bash: /etc/filename.conf: Permission deniedTo prevent the above output, simply prepend sudo before the tee command as shown in below command:
echo "hello" | sudo tee -a /etc/filename.confWhen you run the above command, tee command will receive the output of the echo command and write it to the file.
That’s all
If you face any error and issue in above steps , please use comment box below to report.
If our tutorials helped you, please consider buying us a coffee. We appreciate your support!
Thank you for your support.



