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
    → [email protected] -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 will take over and send the file to the boss. See Chapter 11 for more on fancy mail tricks.

Tee Time?

You might think of the tee command as being similar to a plumber’s pipe joint— that is, it takes stuff from one location and sends it out to two different places.


Code Listing 6.19. Use tee to send output to two different places at once.
[ejr@hobbes manipulate]$ sort address.book new.addresses | tee sorted.all | mail[email protected] -s  "Here's the address book boss" -
						[ejr@hobbes manipulate]$
					

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.236.174