How to suppress warning or error messages in find command

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.

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

Leave a comment

Your email address will not be published. Required fields are marked *