How to ignore "find: cannot read dir /foo: Permission denied"

Published:

If you run the following command on a Unix system, depending on your permissions and other stuff, you might see a lot of errors.

$ find / -name "tar"

In my case I got 8 regular findings and 63 lines of "find: cannot read dir /foo: Permission denied". Quite a lot of noise I really don't care about. Using my new knowledge about streams it is easy to get rid of all that though. Just pipe stderr into /dev/null.

$ find / -name "tar" 2>/dev/null

Voila. Clean output.

⚠ Remember that when you do this all errors will be sent to nowhere. So if there were any other errors, they would also be gone. In this case I don't care, but in other instances you might want to do something else. For example direct it to a log file rather than to oblivion.

Alternative

If you do care about other error messages, you could do as suggested by Richard in the comments: Redirect stderr to stdout and then use grep to filter out what you don't want to see.

$ find / -name "tar" 2>&1 | grep -v "Permission denied"