Redirecting to Multiple Locations with tee

Suppose you just updated your address book file and want to send it to your boss in addition to putting it in your own files. You can, using tee, which redirects output to two different places (see Code Listing 6.19).

To redirect output to two locations with tee:

  • sort address.book new.addresses
    → | tee sorted.all | mail
    → boss@raycomm.com -s "Here"s the
    → address book, boss" -
    

    At the shell prompt, use the tee command plus a filename in the middle of the pipe line to send the sorted information to that filename as well as to the standard output (which could, of course, be redirected to another filename). Here, we send the results of the sort to the sorted.all file and to standard output, where mail ...

Get Unix Third Edition: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.