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
...