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" > linuxg.net
$ cat linuxg.net
hello linux geeksters

Redirect stdin to stdout with tee:

$ echo "hello linux geeksters" | tee linuxg.net
hello linux geeksters
$ cat linuxg.net
hello linux geeksters

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

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

Liked it? Take a second to support Geekster on Patreon!
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

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

*

Support LinuxG via Patreon
Support LinuxG.net on Patreon!
Subscribe

  

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