Home > bash > The tee command

The tee command


You have a program/script that prints some output to the stdout. You redirect the output to a file but since the execution time is slow, you would like to see its progress too on the standard output. That is, redirect the output to a file and to the standard output too.


You’ll need the tee command. Example:

C:\tmp> date >d.txt
C:\tmp> date | tee e.txt
Wed Mar 30 22:40:22 EDT 2011
C:\tmp> cat e.txt 
Wed Mar 30 22:40:22 EDT 2011

It was a simpe example. As I mentioned, it is more useful when you run a program whose execution time is slow. This way you can see its partial results.

It can happen that you see no output on the stdout. You know that the program should have printed something, but nothing appears on the stdout. It’s because of buffering. When you use a pipeline, the shell will do some buffering. If you don’t need that, you can use autoflush in your program/script.

Alternative way:
If you already launched the program (and redirected its output to a file) and you don’t want to restart it with tee, there is another solution. You can monitor the changes of the output file with “tail -f output.txt“. It will print the contents of the file till its end and it will be waiting. When some new lines are added to the file, “tail -f” will print them and wait, etc. Since it never quits, you can terminate it with CTRL+C.

Categories: bash Tags: , , , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: