How to use the tee command to display and save the output file?

  • Post last modified:December 31, 2020
  • Reading time:2 mins read

What tee command? It will show output on the terminal and even the file is getting save into a specific location and you do not need to create a file it will automatically generate.

To get into more detail we will use this “tee” command to demonstrate.

Read this:- Latest:2020 How to Mount and Unmount File System in Linux?

Syntax

command | tee filename.txt
 save the command output from the Linux terminal
and How to use tee command?
How to use tee command?

We will use hostnamectl command to show machine details with tee to save output into trendoceans.txt

How to append output using tee command?

If you want to save file output again and again into same file then you have to append the file.

In case you have just tee with the option then file we will get overwritten, To get into more detail we will use this “tee -a” command to demonstrate.

Syntax

command | tee -a filename.txt
How to use |tee  -a command?
How to use |tee -a command?

You can see in picture both the output are save in single file

Now we will show you how you can save error output and standard output into a file.

Syntax without append

command | &tee filename.txt

Syntax with append

command | &tee -a filename.txt
How you can save error output use |&tee command?
How you can save error output use |&tee command?

Like this way you can save error and standard using |& tee command.

Wrap up

We have guided how to use the redirect symbol and tee command to save command output into a file.

There are combination of redirection symbol which you can use like “>” ,“>>”,“&>”,”&>>.

Combination of tee command |tee, |tee -a, |&tee, |&tee -a.

Let’s us know If you want to know much about any specific topic.

Through all the above method, you can save the command output from the Linux terminal.

Like what you read? Please share it with others.
  • 1
    Share
guest
0 Comments
Inline Feedbacks
View all comments