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

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 was 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.


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"
  • Richard
    $ find / -name "tar" 2>&1 | grep -v "Permission denied"
    • Smart! Thanks for sharing 🙂