Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I would like to direct:

  • Standard out to file.
  • Standard error to the same file.
  • Standard error to console (as well as file).

I've seen this kind of thing:

mycommand 2>&1 | tee test.txt

But it shows standard out on the console where I only want to see errors.

Any help would be appreciated.

share|improve this question
up vote 1 down vote accepted

This is not optimal but it should do:

exec 3>mylogfile; mycmd 2>&1 >&3 | tee >(tee >&3);exec 3>&-;

have fun playing with this.

share|improve this answer
Thanks for this. Seems to work ok on most of our scripts. Have got one script which I'm running with this, which just hangs until I Ctrl-C it. It finishes straight away without the "tee >(tee >&3)" bit, but hangs around when that bit is there. Will debug it a bit more. – Ben Apr 6 '11 at 0:24

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.