Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Okay. If I wanted to redirect the output of a program to a file, I'd do something like this

prog > file

If I wanted to redirect both stdout and stderr to that file, then I'd do

prog > file 2>&1

This is all well and good if you want the output to go to the file. But what if you want the output to go to the file and yet still go to stdout/stderr? So, the output is saved in the file, but you can still see it on the console as the program is running. Is there a way to do that? And if so, how?

share|improve this question
up vote 37 down vote accepted

tee exists for this purpose; it takes a filename argument and writes the data it reads from stdin to both stdout and the file:

$ prog 2>&1 | tee file
share|improve this answer
And for extra bash 4 cuteness: prog |& tee file. – Tobu Nov 19 '10 at 1:49
You can also replace 'file' with a named pipe... – Kevin Cantu Nov 30 '10 at 2:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.