5.5. tee

The tee command acts the way it is pronounced. It takes the input and sends one copy to the standard output and another copy to a file. If you want to see your output and save it to a file at the same time, then this is the command for you.

The general format is:

tee -a files 

where, ‘-a’ means append all output to a file.

Tee comes in handy when you are running commands or scripts and you want to keep a log of the output.

Let’s look at an example. Using the who command, the output is sent to the screen and a copy is sent to a file called who.out.

						$ who | tee who.out louise pts/1 May 20 12:58 (193.132.90.9) matthew pts/0 May 20 10:18 (193.132.90.1) cat who.out louise pts/1 May 20 12:58 (193.132.90.9) matthew pts/0 May 20 10:18 (193.132.90.1) ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.