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.
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.