Home » Linux

Read from a standard input and write to a standard file

30 June 2013 No Comment
VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)

Golf Tee

In golf, a tee is a stand used to support a stationary golf ball so that a player can strike it. In Unix, a tee is a program used to read a standard input and write to a standard output and file.

What is the commonality between golf tee and Unix tee? They are both helpers. They don’t perform by themselves. Just as a golf tee supports the golf ball, Unix tee helps support the command you are running.

The following shows the syntax for tee.

tee [-ai] [file(s)]

-a          Append the output to one or more files rather than overwriting them.

-i          Ignore interrupt signals.

Examples:

ls *.png | tee imagelist.txt

In the above example, the ls command lists all the .png files in the current directory. The output will be saved to the imagelist.txt file.

grep home HomePrices.txt | wc -l | tee home1.txt home2.txt

In the above example, the grep command finds all the occurrences of the word home in the text file. Then it does a word count to get the total lines found. Finally, it saves the output to two files called home1.txt and home2.txt. Both files will be identical.

ls -l *.txt | tee -a text_listing.txt

In the above example, the ls command lists all the .txt files in the current directory. The output is appended to the file text_listing.txt. If the file does not exist, it creates a new file.

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.