How to suppress warning or error messages in find command

Last updated on June 5, 2020 by Dan Nanni

If you have used find command on Linux, you probably have encountered the case where the command ends up producing an endless list of warning or error messages in its output, because you are "permission denied" to access certain files or directories.

$ find / -name "my.txt"
find: `./proc/18/task/18/fd': Permission denied
find: `./proc/18/task/18/fdinfo': Permission denied
find: `./proc/18/task/18/ns': Permission denied
find: `./proc/18/fd': Permission denied
find: `./proc/18/fdinfo': Permission denied
find: `./proc/18/ns': Permission denied

Such output is probably meaningless to you, so you may want to exclude these warning or error messages from the output, and get actual search result only. How can you suppress warnings or errors, and only get search result in find command?

The find command sends any error or warning message to standard error output (i.e., stderr). So all you have to do to suppress these messages is to redirect stderr to /dev/null.

The following is how to suppress all warnings or errors in find command.

$ find . -name "my.txt" 2>/dev/null

If you want to capture stderr output in a separate file for later inspection, you can do the following instead.

$ find . -name "my.txt" 2> find_error.txt

If you want to exclude specific warnings only, you can filter out warning messages from stderr selectively by using grep, instead of redirecting the whole stderr. For example:

$ find . -name "my.txt" 2>&1 | grep -v "Permission denied"

The above command will suppress only "Permission denied" warning message, and show any other warning or error messages unfiltered.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean