Using tee for redirexction

Have you ever wanted to capture the output of a command to a file, but also send it to the screen? The command tee can do just that. Suppose you have a script that builds your application called compile and it sends pages of output to your screen, so you want to capture it to a file so that can employ UNIX's ability to search for patterns. You can achieve this using the UNIX commands

./compile >& filename

where the redirection symbols >& direct both the standard output (stdout) and write error output to standard error (stderr) to the file named filename. Sometimes you also want to see the output on the screen at the same time. This is where the Unix command tee comes in. For example the Unix commands

./compile |& tee filename

redirects both stdout and stderr to the file filename.

No comments:

Post a Comment