Suppress errors in bash/zsh
Sometimes, I need to run a command in terminal that will cause a TON of
expected error messages. This is the case, for instance, when searching for a
file on the entire disk: trying to traverse the tree from root will encounter
many errors, because of permissions or other conditions.
The sheer amount of noise makes those searches almost useless, and that’s
the reason why I seldom used them.
But actually, there is a very simple solution! Errors go to STDERR, so we
can just redirect it. Knowing that STDERR is the second file handle, it
means something like appending 2>/dev/null
to the command.
E.g.:
find / -name catch_test_macros.hpp # A lot of "Permission denied" / "Operation not permitted" errors
find / -name catch_test_macros.hpp 2>/dev/null # just the required results, after few seconds
Thanks to the Unix and Linux StackExchange for helping in finding the correct approach!