Dev Null

less than 1 minute read

Description:

Many times when modifying scripts from the internet you will see lines where they put “something something command -argument 2>/dev/null;” and you may wonder what it means.

To Resolve:

  1. When they do this, they are simply redirecting stderr to a file, which in this case, is *nix’s black hole file. Whatever goes into it cannot be seen or retrieved.

  2. Here is a good explanation (copied and pasted in case source gets deleted):

    • If you don’t specify a number then the standard output stream is assumed but you can also redirect errors

    • > file redirects stdout to file
    • 1> file redirects stdout to file
    • 2> file redirects stderr to file
    • &> file redirects stdout and stderr to file

    • /dev/null is the null device it takes any input you want and throws it away. It can be used to suppress any output.
  3. To see the difference between stdin, stdout, and stderr => just use wikipedia!

Tags:

Updated:

Comments