Displaying program output and copying to a file (tee command)

The tee command, used with a pipe, reads standard input, then writes the output of a program to standard output and simultaneously copies it into the specified file or files. Use the tee command to view your output immediately and at the same time, store it for future use.

For example, type the following:
ps -ef | tee program.ps
This displays the standard output of the ps -ef command on the display device, and at the same time, saves a copy of it in the program.ps file. If the program.ps file already exists, it is deleted and replaced unless the noclobber option of the set built-in command is specified.
For example, to view and save the output from a command to an existing file:
ls -l | tee -a program.ls
This displays the standard output of ls -l at the display device and at the same time appends a copy of it to the end of the program.ls file.
The system displays information similar to the following, and the program.ls file contains the same information:
-rw-rw-rw-   1 jones   staff   2301   Sep 19    08:53 161414
-rw-rw-rw-   1 jones   staff   6317   Aug 31    13:17 def.rpt
-rw-rw-rw-   1 jones   staff   5550   Sep 10    14:13 try.doc