Blocking errors completely

A common idiom to ignore error output from commands is to discard it by directing it to the special /dev/null device file, which just ignores anything written to it and is always empty:

$ grep pattern myfile /nonexistent > matches 2> /dev/null

If you want to ignore error output, this works, but think carefully before you do this. Error messages are written to let you know and to help you understand when something is not working, and they assist in debugging, especially when the error isn't fatal  that is, when the command still runs to completion and maybe generates some output, so if nobody sees the errors, it might seem like everything is working fine.

A good example is the comm tool, which shows lines that differ ...

Get Bash Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.