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.

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

Tagged with: , , , ,
Posted in The Linux and Unix Articles!
2 comments on “How to Use the Tee command In Linux And Unix Operating Systems
  1. VIVEK says:

    GOOD WRK..

Leave a Reply to VIVEK Cancel reply

Your email address will not be published. Required fields are marked *




Subscribe to get the latest Linux news and how to guides directly on your e-mail!