I'm using bash script on AMazon Linux. When I want to redirect stderr and stdout to a file, I can run

./my_process.pl &>/tmp/out.txt

Is there a way I can redirect this output to a file and continue to see it on the console (in my shell)? How is this done?


2 Answers 2


Yes, by using tee:

/my_process.pl 2>&1 | tee /tmp/out.txt

Note that using &>file for redirecting both standard output and standard error to a file is an extension to the POSIX standard that is accepted by some shells. It is safer to use >file 2>&1. In this case, &> can not be used at all since we're not redirecting to a file.

In bash, one may also do

/my_process.pl |& tee /tmp/out.txt

which is equivalent of the above. In ksh93, |& means something completely different though.


Use the script commands this will store both stdin and stdout in a file called typescript.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .