I wish to redirect standard error of one command to standard input of another command like

g++ filename.cpp 'redirection' less

1 Answer 1


You can use pipe to do that

command1 2>&1 >/dev/null | command2

It will redirect the standard error stream of the first command to the standard input stream of the second command while discarding the standard output stream of command1.

The redirections are done in order:

  1. command1 2>&1 will redirect file descriptor 2 (standard error) to wherever file descriptor 1 (standard output) is connected.

  2. >/dev/null (the same as 1>/dev/null) will redirect standard output to /dev/null.

In your case:

g++ filename.cpp 2>&1 >/dev/null | less
  • 1
    Is there a way to shorten "2>&1 >/dev/null" to something which can be typed shortly I tried alias but it didn't work out .
    – vib_29
    Mar 17, 2019 at 10:43

You must log in to answer this question.

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