Tee command in Linux is used to take the input from Standard input & prints the output to both screen & to one or more files or even can be used as input for variables, which can be used further in Bash script etc.

In this tutorial, we will learn how to use the TEE command in Linux with the help of examples.

Recommended Read: Essential Linux Commands You Should Know

Also Read: Linux commands you should never run on your system


TEE command in Linux

TEE command in Linux


Syntax for using the TEE command in Linux is as follows,

# tee [OPTION] [FILE]

https://services.vlitag.com/vpaid/?q=9ba3f2539ddb6b2df45a4f25fbfd7843&defaultVolume=&page_url=https://linuxtechlab.com

Now let’s discuss the practical use of the TEE command in Linux.

 

1- Writing output to an file

To save the output of a command to a file & also show the output on the screen, the complete command is,

# free -m  | tee memory_output.txt

So here we will see the output of ‘free -m’ on screen as well it will be copied in the file named ‘memory_output.txt’

 

2- Overwriting the output to same file

If we run the same command again, the command will overwrite any content that might have been on the file. We can prevent it by using the option ‘-a’,

# free -m | tee -a memory_output.txt

 

3- Write output to multiple files

With tee command, we have option to copy the output to multiple files as well & this can be done as follows,

# free -m | tee output1.txt output2.txt

 

4- Suppress the output

We can also suppress the output of a command to system screen & only save the output to a file with the following command,

# free -m | tee output1.txt > /dev/null

 

5- Ignore any interrupts

There are instances where we might face some interruptions while running a command but we can suppress that with the help of ‘-i’ option,

# ping -c 3 | tee -i output1.txt

 

6-  Getting help for tee command in Linux

To get help or the complete list of information for all the options that can be used with tee command, we can get the help with the following command,

# tee --help

With this we end this tutorial on how to use the TEE command in Linux. Please do let us know if you have any questions or queries using the comment box below.

We are giving you exclusive deals to try Linux Servers for free with 100$ credit, check these links to claim your 100$,

DigitalOcean - 100$ free credit & Linode - 100$ free credit

Check some Exclusive Deals, HERE.

Also, check out DevOps Book You should read section.