What `2>/dev/null` Does

I kept seeing commands ending with 2>/dev/null in scripts and agent runs. I knew it had to do with suppressing output, but I never stopped to parse what each character actually does.

My first guess was that 2 meant running something in the background or piping into a second stage. It does not.

2 is the standard file descriptor for stderr, the stream where programs print errors, warnings, and diagnostic noise. The three default streams are:

  • 0 for stdin (standard input)
  • 1 for stdout (standard output)
  • 2 for stderr (standard error)

The rest of the syntax breaks down into two parts:

  • > redirects the stream on the left to the target on the right.
  • /dev/null is a special device file that discards everything written to it.

So 2>/dev/null sends stderr straight to the trash. It does not run in the background, and it does not pipe to another command. It just keeps error messages off your screen.

It helps to contrast it with other common shell operators:

  • | feeds stdout into the next command.
  • & at the end runs the command in the background.

2>/dev/null does neither. It only mutes error output.

Here is a common example:

find . -name node_modules 2>/dev/null

When find hits directories without read permissions, it floods the terminal with Permission denied lines. Appending 2>/dev/null drops those errors while letting valid search results print as normal.

Another pattern that shows up often is >/dev/null 2>&1, which silences both standard output and errors.

The 2>&1 part redirects file descriptor 2 (stderr) to wherever file descriptor 1 (stdout) is currently going. Since stdout is pointed at /dev/null, stderr ends up discarded too. Modern shells like Bash 4+ and Zsh also support the shorthand &>/dev/null to do the same thing.