DEV Community

Kenneth Lum
Kenneth Lum

Posted on

Silence the errors in Bash or Zsh

Sometimes we may want to silence the errors in Bash or Zsh, such as when using find and we don't want the "Permission denied" messages to clobber up the results. The 2> /dev/null or 2>&- can be added to the command

sudo find / -name opendiff 2> /dev/null
Enter fullscreen mode Exit fullscreen mode

or

sudo find / -name opendiff 2>&-
Enter fullscreen mode Exit fullscreen mode

The 2 above is the file descriptor for the standard error stderr. /dev/null is the "null device" (also called the bit bucket or black hole). The >&- is to close the file descriptor, and 2>&- is to close stderr.

Top comments (0)