Wednesday, May 16, 2007

Unix: tee

As defined from the man page for tee:
tee - replicate the standard output

tee [-ai] [file...]

The tee utility will copy standard input to standard output,
making a copy in zero or more files. tee will not buffer its
output. The options determine if the specified files are
overwritten or appended to.

The following options are supported.

-a Append the output to the files rather than overwriting

-i Ignore interrupts.

It's useful for when you want to capture a log of whatever command you are running, but still want to see the output. This was handy for me today when running some scripts from the vendor, which had the possibility to throw errors during the process which I would need to kill. I wanted to make sure to log everything, but was able to still see the problems as they occurred.

Example of usage.
> ./ | tee install.log


> ls

This will put the output of the script to the standard output (screen) as well as write that to the install.log file.

No comments: