[Next] [Previous] [Up] [Top] [Contents]

8.1 Working With Files

8.1.9 tee - copy command output

tee sends standard in to specified files and also to standard out. It's often used in command pipelines.

Syntax

tee [options] [file[s]]

Common Options

-a append the output to the files

-i ignore interrupts

Examples

In this first example the output of who is displayed on the screen and stored in the file users.file:

brigadier: condron [55]> who | tee users.file

condron ttyp0 Apr 22 14:10 (lcondron-pc.acs.)

frank ttyp1 Apr 22 16:19 (nyssa)

condron ttyp9 Apr 22 15:52 (lcondron-mac.acs)

brigadier: condron [56]> cat users.file

condron ttyp0 Apr 22 14:10 (lcondron-pc.acs.)

frank ttyp1 Apr 22 16:19 (nyssa)

condron ttyp9 Apr 22 15:52 (lcondron-mac.acs)

In this next example the output of who is sent to the files users.a and users.b. It is also piped to the wc command, which reports the line count.

brigadier: condron [57]> who | tee users.a users.b | wc -l

3

brigadier: condron [58]> cat users.a

condron ttyp0 Apr 22 14:10 (lcondron-pc.acs.)

frank ttyp1 Apr 22 16:19 (nyssa)

condron ttyp9 Apr 22 15:52 (lcondron-mac.acs)

brigadier: condron [59]> cat users.b

condron ttyp0 Apr 22 14:10 (lcondron-pc.acs.)

frank ttyp1 Apr 22 16:19 (nyssa)

condron ttyp9 Apr 22 15:52 (lcondron-mac.acs)

In the following example a long directory listing is sent to the file files.long. It is also piped to the grep command which reports which files were last modified in August.

brigadier: condron [60]> ls -l | tee files.long |grep Aug

1 drwxr-sr-x 2 condron 512 Aug 8 1995 News/

2 -rw-r--r-- 1 condron 1076 Aug 8 1995 magnus.cshrc

2 -rw-r--r-- 1 condron 1252 Aug 8 1995 magnus.login

brigadier: condron [63]> cat files.long

total 34

2 -rw-r--r-- 1 condron 1253 Oct 10 1995 #.login#

1 drwx------ 2 condron 512 Oct 17 1995 Mail/

1 drwxr-sr-x 2 condron 512 Aug 8 1995 News/

5 -rw-r--r-- 1 condron 4299 Apr 21 00:18 editors.txt

2 -rw-r--r-- 1 condron 1076 Aug 8 1995 magnus.cshrc

2 -rw-r--r-- 1 condron 1252 Aug 8 1995 magnus.login

7 -rw-r--r-- 1 condron 6436 Apr 21 23:50 resources.txt

4 -rw-r--r-- 1 condron 3094 Apr 18 18:24 telnet.ftp

1 drwxr-sr-x 2 condron 512 Apr 21 23:56 uc/

1 -rw-r--r-- 1 condron 1002 Apr 22 00:14 uniq.tee.txt

1 -rw-r--r-- 1 condron 1001 Apr 20 15:05 uniq.tee.txt~

7 -rw-r--r-- 1 condron 6194 Apr 15 20:18 unixgrep.txt


Introduction to Unix - 14 AUG 1996
[Next] [Previous] [Up] [Top] [Contents]