Untitled Document
tee Command

The tee is an external command and not a feature of the shell .It saves one copy in a file and writes the other to standard output . Being also a filter ( which uses standard input and standard output ) tee can be placed anywhere in a pipeline . tee doesn't perform any filtering action on its input , it gives out exactly what it takes .

1. Basic Example -

The following command sequence uses tee to display the output of who nad saves this output in a file as well

   who | tee user_loggedin.txt   

2. Displaying the user count and list of user on terminal -

The below tee command saved the who output in /dev/tty , thus effectively showing it on screen . wc -l counted the other stream . The advantage of treating the terminal as a file is apparent from the above example .

   who | tee /dev/tty | wc -l 

3. Storing first 10 lines of emp.csv in emp_details.txt

Run below command and see the results

   head -n 10 emp.csv | tee emp_details.txt
Untitled Document