Bobcares

Ignore permission denied message from find command in Linux

by | Mar 11, 2021

While running find command, received an error ‘ignore permission denied message from find’? We can help you.

Here at Bobcares, we have seen several such Linux-related errors as part of our Server Management Services for web hosts, Linux users, and online service providers.

Today we’ll take a look at the cause for this error and see how to fix it.

 

Find command basic syntax

For instance, the syntax is as follows:

find where-to-look criteria action
find /dir/to/search -name filetosearch
find /dir/to/search -name "*.c"
find /home/nixcraft/project/ -name "*.py" -print

In this example, find will search the /tmp directory for any files named “data*.txt” and display their pathnames:

find /path/to/dir -name "pattern" -print
find /tmp -iname "data*.txt"

OR

cd /tmp
find . -iname "data*.txt" -print

 

How we tackle ‘ignore permission denied message from find’

Now let’s take a look at how our Support Engineers tackle the error when executing the find command.

Recently, one of our customers was trying to execute the below find command in Linux/Unix and received “Permission denied” error messages.

find . -type d -name “bob”

So, we can hide or fix find command permission denied messages. Here is how we do it.

 

How to hide or fix find command permission denied messages

In the above example, we don’t have the read permission for vmware-root and orbit-Debian-gdm directories. So, we use the below syntax to avoid the problem.

## redirect error spam message to /dev/null ##
find where-to-look criteria action 2>/dev/null
find . -iname "data*.txt" -print 2>/dev/null

Here is the output without permission denied spam from find command:

./rtzip/data005.txt
./rtzip/data001.txt
./rtzip/data004.txt
./rtzip/data003.txt
./rtzip/data002.txt
./rtzip/data008.txt
./rtzip/data006.txt
./rtzip/data007.txt
./rtzip/data009.txt

Here, at the end of the find command 2>/dev/null tells the shell to redirect the error messages (FD #2) to /dev/null, so we don’t have to see them on screen. We use /dev/null to send any unwanted output from program/command. The system discards all data written on a /dev/null special file. To redirect standard error to /dev/null and store file list to output.txt, we type:

redirect error spam to /dev/null ##
find . -iname "data*.txt" -print 2>/dev/null > output.txt
cat output.txt

 

Exclude all “permission denied” messages from the “find” command on Linux

The one problem with the following command is that it would filter out all error messages created by the find command and not just the permission denied ones:

find / -name foo 2>/dev/null
find / -type d -name bar 2>/dev/null

In order to avoid that, we try the following find command along with grep command on Linux or Unix-like systems:

find / -name foo 2>&1 | grep -v "Permission denied"
find / -type d -name bar 2>&1 | grep -v "Permission denied"

Also, we can use the below syntax to skip “permission denied” errors messages when running find in Linux or Unix-based systems:

find /path/to/dir -name "search-patter" 2>&1 | grep -v "Permission denied"
find /etc -name "x*.conf" 2>&1 | grep -v "Permission denied"

To store output to a file, we run:

find /path/to/dir -name "search-patter" 2>&1 | grep -v "Permission denied" > output-file
find /etc -name "x*.conf" 2>&1 | grep -v "Permission denied" > output.txt

Then we display output.txt using the cat command:

cat output.txt

In the above example, we used the find command along with grep command to filter out permission denied error messages.

[Need any further assistance in Linux-related errors? – We’re available to help you]

 

Conclusion

In short, this error ‘ignore permission denied message from find’ occurs while running a ‘find’ command in Linux. Today, we saw how our Support Engineers resolve this error.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.