Home » linux » Linux and Unix tee command tutorial with examples

Linux and Unix tee command tutorial with examples

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.

Example:

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.

File: Data.txt

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.

File: User.txt
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 :

  1. By using cat command
  2. By using cmp (comparison) command

1. By using cat command: cat command display the content of file by which we sure.

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.

Here cmp command compares the output of “ $ cat Data.txt ” to the content of User.txt file.

Please follow and like us:
error