Command tee displays the output of the command and at the same time it saves this output in a file specified by the user.
“tee” command can be used anywhere along with pipeline.
Suppose we have a file Data.txt as shown below and we want to see the content of this file and at the same time save the output/content of the file in a new file User.txt.
We can see the content of the file by using “cat” command.
$ cat Data.txt|tee User.txt [press enter]
I am Aditya
From NIT Patna
Asst. Prof(SSEC BHILAI)
In the above command “cat” will display the content of file Data.txt at the terminal and “tee” command will save this content on Data.txt file as shown below file. If the User.txt does not exist it will create automatically.
The user.txt file contains the content of file Data.txt but how we can sure. There are two way to confirm that User.txt file contains the content of file Data.txt :
- By using cat command
- By using cmp (comparison) command
1. By using cat command: cat command display the content of file by which we sure.
$ cat User.txt [press enter]
2. By using cmp (comparison) command: cmp command compares two files byte by byte. If both files is same/identical cmp command will display no message and simply return the prompt.
$ cat Data.txt| cmp User.txt [press enter]
Here cmp command compares the output of “ $ cat Data.txt ” to the content of User.txt file.