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 file name in the middle of the pipeline to send the sorted information to that file name as well as to the standard output (which could, of course, be redirected to another file name). Here, we send the results of the sort to the sorted.all file and to standard output, where mail ...

Get Unix: 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.