Полезная информация

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 13.8 Using {list} to Group Bourne Shell Commands Chapter 13
Redirecting Input and Output
Next: 13.10 How to tee Several Commands Into One File
 

13.9 Send Output Two or More Places with tee

tee
If you're running a program and you want to send its output to a file - but you want to see the output on your screen, too, so you can stop the program if something goes wrong - you can use tee. The tee program reads its standard input and writes it to one or more files. (The CD-ROM has the GNU version.)

NOTE: A pipe may buffer the output of a program, collecting it in chunks and spitting it out every so often. If the program's output comes slowly and feeds tee through a pipe, there might be long delays before you see any output. In that case, it's better to use > to redirect output to a file, put the program into the background, and watch the output with tail -f (25.16). Or use a program like script (51.5).

Use tee for saving results in the middle of a long pipeline of commands. That's especially good for debugging. For example, you could type:

% prog | tee prog.out | sed -f sedscr | tee sed.out | ...

to save the output of prog in the file prog.out and also pipe it to the sed command, save sed's output in sed.out and also pipe it...

If you want to add to a file that already exists, use the -a option:

... tee -a filename ...

- JP


Previous: 13.8 Using {list} to Group Bourne Shell Commands UNIX Power ToolsNext: 13.10 How to tee Several Commands Into One File
13.8 Using {list} to Group Bourne Shell Commands Book Index13.10 How to tee Several Commands Into One File

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System