The tee command

Note this command, very useful one

Command : tee

About tee:

** Read from an input and write to a standard output or file.

Eg: ls *.txt | wc -l | tee /dev/tty count.txt

Sample O/P

nazeem@111:~$ ls *.txt | wc -l | tee /dev/tty count.txt
7
7
nazeem@111:~$

** ls command would list all .txt files in the current directory, take a word count and the output displayed to the /dev/tty (terminal) will be sent to the count.txt.

** One of the important use of tee was that it can use  see intermediate out put of each portion in complex commands and also you can generate intermediate log file using tee command.

Eg:

nazeem@111:~$ ls *.txt |tee count.txt | wc -l
7
nazeem@111:~$ cat count.txt
a.txt
count.txt
load.txt
ls.txt
m.txt
server.txt
test.txt
nazeem@111:~$

Here the intermediate o/p was written to the file count.txt

** You can also print the intermediate o/p on terminal via

nazeem@111:~$ ls *.txt |tee /dev/tty | wc -l
a.txt
count.txt
load.txt
ls.txt
m.txt
server.txt
test.txt
7
nazeem@111:~$

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: