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'm watching the output of my complicated command with less, problem is the stderr gets lost. stderr lines normally get listed inbetween stdout lines inside less. I would like them to be printed to the console, and when I exit less, to see them there together.

I realize there might be no solution to this, I read about tee and multitee but no luck so far.

share|improve this question

migrated from Dec 10 '11 at 14:29

This question came from our site for professional and enthusiast programmers.

You're telling me how to redirect stderr to stdout but that's not what I wanted. I don't want stderr to mix with stdout inside less. I would like stderr to be in the terminal when I exit less. – haelix Dec 10 '11 at 14:17
If stderr is redirected to stdout, all output to stderr will be mixed with the normal output on stdout. Piping that output to less will show both. – Joachim Pileborg Dec 10 '11 at 15:15
If I ignore "stderr to be in the terminal when I exit less", I suggest to press Ctrl-L in less to repaint the screen. – kamae Dec 13 '11 at 13:40
up vote 5 down vote accepted


command 2> command.err | less; cat command.err; rm command.err
share|improve this answer
Thanks man, this is the effect I was trying to achieve. – haelix Dec 10 '11 at 15:58

You have to redirect stderr to stdout:

$ ./somecommad 2>&1 | less

Check the manual for you shell (e.g. man bash.)

share|improve this answer

just tell the shell to redirect fd 2 to fd 1 (stderr to stdout)

 make 2>&1 | less
share|improve this answer

You need to understand the concept of "file descriptors". Usually, a unix application will start with three special file descriptors:

  • Standard input
  • Standard output
  • Standard error

The "pipe" | in the shell connects stdout from one process with stdin of the next.

Errors are - by design - not fed to stdin of the next process. They will often not make sense to the next application, and should not be hidden from the user.

If you want to mix the errors into stdout, you can use e.g. 2>&1, which says essentially "append stderr to stdout". For example

find /etc 2>&1 | less

should also include error output from inaccessible files.

find /etc 2>&1 >/dev/null | less

will give you the errors only.

share|improve this answer

I'm confused about your question, as far as I ca tell your desired behavior is the default.

When I use

#include <stdio.h>

int main(int argc, char**argv){
  for (int j=0; j<10; ++j){
    fprintf( (j%2 ? stdout : stderr) , "%d\n" , j);
  return 0;

to get a simple test,

$ ./testredirection | less

does just what you ask. That is I see


in less and

$ ./testredirection | less

when I quit less

share|improve this answer
It's strange but things are not always like this. Try with a script (echo info ; echo error 1>&2) and repeat the test: both lines are piped to less. – cYrus Dec 10 '11 at 16:19
@cYrus: That works as expected for me, too. 'Course I tried in on a Mac OS box. Bash 3.2.17, less 394. Maybe something linux specific. In any case RedGrittyBrick's approach should work fine. – dmckee Dec 10 '11 at 16:26
Weird! Debian Squeeze / Bash 4.1.5 / Less 436 – cYrus Dec 10 '11 at 16:32
Yeah, I opened a shell of Scientific Linux 5.3 box at work and got the expected behavior with bash 3.0.15 and less 382. Could there be a regression in there? – dmckee Dec 10 '11 at 16:39
I don't know, I think it's just a matter of buffering. – cYrus Dec 10 '11 at 16:54

I happen to encounter this problem in one of my Debian 5.0's recently. for example, ls abc | less I find that the error message go into less, which against my knowledge.

After some attempts, I found that it is just something related to screen buffers. stderr does NOT go into less actually. You can use Up or Down arrow keys (or j/k) to demonstrate.

share|improve this answer

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.