The Tee command in Linux is mostly used in combination with other commands, it reads the input and in response to that writes the output to one or more files. It does this so that the output can be displayed as well as saved to a file at the same time. In this article, we will learn more about the tee command, from its syntax to its use along with examples to help you understand it better.
Syntax
The syntax of the tee command is provided below. Here in this OPTIONS could be the following:
-a (–append): used to append to add to file and not overwrite it. -i : in order to ignore the interrupt signals.
For [FILE] include the filename which can be one or more than one file.
Tee Command in Linux
The basic way in which the tee command is commonly used is to write to a file and display the output i.e stdout (standard output). Users can write to a single as well as multiple files, hide output, they can append to a file without overwriting it, and also useful to ignore any interrupts while executing the file. Let’s understand these ones by one with examples.
Conclusion
Sometimes the user wants to write the output they get in the terminal to a file and for this purpose, the tee command is used. In this article we told you various ways how the tee command is used in Linux, we can write to multiple files as well as hide output or append to a file without overwriting it. Examples are provided in the case to help you understand the usage better of each command. Now go and check the file “exFile.txt” using the cat command. Now again if you check both the files using the cat command the content will be displayed. In this way, we can write to one or multiple files and save our output for later use. Now we’ll spend the word “World” in it. Now, if we view the file using the cat command we will see that it appended the last word instead of overwriting it over the previous. In this way, we can append it into a file without overwriting it. Later we checked the output using the cat command. In the example, we will ping google and use the interrupt command and while it’s executing we will interrupt it with CTRL+C. Here you can see that while the command was running it was interrupted but still it executed smoothly. We can verify the content was added to the file by viewing the file using the cat command: This way you can have access to the file easily.
![tee Command in Linux with Examples TecAdmin - 1](https://tecadmin.net/wp-content/uploads/2021/10/tee-command-in-linux.png)