How to Use the Tee command In Linux And Unix Operating Systems

Tee is a Linux and Unix command for writting STDIN to STDOUT. It is usefull when you want to redirect STDOUT to a file (or more) and also display it on the screen.

Watch Free Movies

tee -a appends text to files, like >>

tee empties files and adds test, at the beginning, like >

Combined with some commands, tee really does good jobs. I use tee to invoke sudo, inside commands. For example, you can’t sudo echo “something”, so you have to use tee:

This is usefull when adding sources to /etc/apt/sources.list:

$ echo 'some source' | tee -a /etc/apt/sources.list

Or, you can invoke sudo from inside the ViM editor.

Redirect stdin to stdout with > :

$ echo "hello linux geeksters" >
$ cat
hello linux geeksters

Redirect stdin to stdout with tee:

$ echo "hello linux geeksters" | tee
hello linux geeksters
$ cat
hello linux geeksters

This tricks writes “some text” to file1, file2, file3:

$ echo "something" | tee file1 | tee file2 > file3

Scroll to Top