Linux and Unix operating systems mainly managed through command line interface. For complex situations we generally run multiple commands where each command’s output can be input of other commands. Linux provides very useful tool named tee
which provides some flexibility while redirecting command outputs.
Write Output To A File
One of the most popular use case of tee
command is writing command outputs into a file. In this case we will write ls /
command output into file nameddirlist
and also print output to the terminal.
$ ls / | tee dirlist

Append Output To A File
In previous example we have created a file and added provided output. Default behaviour is overwriting to the given file. But in some situations we need to append to the file. We can provide -a
option which will append to the given file.
$ ls / | tee -a dirlist
Write Output Multiple Files
We have the ability to write output multiple files. In this example we will write output to the files named f1
, f2
, f3
, … . We can also add more files.
$ ls / | tee f1 f2 f2
Ignore Interrupts
What if there is an interrupt against tee
. By default the operation and command execution will be finished. We can ignore these interrupts with -i
option like below.
$ ls / | tee -i f1
1 thought on “Linux Tee Command Tutorial with Examples For Stdout Management”