Always redirect error to /dev/null

69,639

Lots of programs send output to stderr that isn't actually indicative of errors. For example, in some programs it is used to display information that would otherwise affect the output of the program (which is designed to be piped into another program). You can, however, do this:

exec 2>/dev/null

I wouldn't recommend doing this outside of a script.

Share:
69,639

Related videos on Youtube

Richard
Author by

Richard

Updated on September 18, 2022

Comments

  • Richard
    Richard almost 2 years

    I know I can redirect the error messages from a command to /dev/null using the following syntax:

    command arg1 arg2 2>/dev/null
    

    But is there a way to do this by default so that the error messages always go to /dev/null, unless I specify otherwise?

    • Benubird
      Benubird about 11 years
      In short: yes - redirect /dev/stderr to /dev/null. But, if you can't figure it out on your own, you shouldn't try, as you are more likely to break something fatally than succeed.
    • clerksx
      clerksx about 11 years
      @Benubird stderr != /dev/stderr. Redirecting that file won't do anything. The file in /dev/ is just for convenience.
    • Benubird
      Benubird about 11 years
      @ChrisDown you're right, /dev/stderr is just a link. Still, a lot of processes write to that instead of fd/2, which you could also redirect. It gets more complicated from there - which is why I left a comment instead of an answer :).