Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

To make it clear, I want to see the output of a command in the terminal as if there were no redirection. Also stderr need to be redirected to err.log and stdout need to be redirected to stdout.log.

It would be also nice to have the exact copy of what is shown in terminal, i.e errors printed as and when it occurs in a seperate file stdouterr.log.

share|improve this question
This is a duplicate of this question –  Nuno C. Inácio Jan 25 '11 at 14:12
@Nuno No it's not. The OP wants to have different files for stdout and stderr. –  dogbane Jan 25 '11 at 14:12
@dogbane Yes, you're right. Sorry about that. –  Nuno C. Inácio Jan 25 '11 at 14:12
I still find this question very familiar. Let me look up... Here is a very similar one unix.stackexchange.com/q/4195/250, and here is a related one unix.stackexchange.com/q/1416/250 –  phunehehe Jan 25 '11 at 15:57

4 Answers 4

up vote 19 down vote accepted

Use the tee command as follows:

(cmd | tee stdout.log) 3>&1 1>&2 2>&3 | tee stderr.log

3>&1 1>&2 2>&3 is how you swap stderr and stdout, because tee can only accept stdout.

Take a look at Unix tee command for more advanced redirections using tee.

share|improve this answer

I think logging stdout and stderr to two different files is a splendid idea. Does it not make the logs asynchronous? So I tried out the following:

  • stdout to "stdout.log" (as dogbane suggested)
  • stderror to "stderr.log" (as dogbane suggested)
  • all output to "all.log" and
  • still be able to see the output on the display (in a separate terminal though!)

((cmd | tee stdout.log) 3>&1 1>&2 2>&3 | tee stderr.log) &> all.log

in another terminal

tail -f --sleep-interval=2 all.log
share|improve this answer
Is it not possible to direct stderr directly to a second tty? Then no logfile is required. –  Steven Lu Apr 25 '13 at 18:40

@dogbane, Thanks.
I found another way too which saves both the streams approximately in the order as they would get printed without redirection.

command 2> >(tee errlog | tee -a bothLog > /dev/tty ) | tee outlog | tee -a bothLog

But this works only with the shells which supports process substitution.

share|improve this answer

try this :

command 2>&1 | tee bothLog
share|improve this answer
Hello vasile, this doesn't answer the question: balki needs separate files for stdout and stderr, your solution would mix both in the same stream. –  Mat Nov 1 '12 at 10:45

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.