Pages

Wednesday, May 16, 2007

Unix: tee

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

SYNOPSIS
tee [-ai] [file...]

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

OPTIONS
The following options are supported.

-a Append the output to the files rather than overwriting
them.

-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.
> ./install.sh | tee install.log

...

> ls
install.log

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

No comments: