The tee Command

tee

The tee command writes the text that is passed to it to a file, and then passes it to standard output — generally the output will be piped to another command.

Here is an example of the tee command:

cat access.log | grep 'msnbot' | tee msn_access.log | egrep '(jpg|png|gif)' > msn_image_access.log

The above example does the following:

  1. cat is used to output the contents of a logfile.
  2. Then all of the lines containing msnbot are extracted with grep
  3. The tee command writes the input that it recieves to a file called msn_access.log, and then passes the same output the the next command.
  4. Egrep extracts lines from the msnbot lines that contain the text jpg, png, or gif (i.e., images files).
  5. The output is then written to a file called msn_image_access.log.

The result is two new log files — one containing hits from msnbot, and the other containing only msnbot's requests for images on the site.

(NOTE: the above example is not going to be highly precise, but it is simplified so that it doesn't get too confusing.)

You can also use tee to write output to a file and to the screen at the same time like this:

grep 'Googlebot' access.log | tee googlebot_access.log
Syndicate content