×


Ignore permission denied message from find command in Linux

Are you facing an error 'ignore permission denied message from find' while running find command in Linux?

This guide will help you.

While using Linux, you may encounter the error, "permission denied".
This error occurs when the user does not have the privileges to make edits to a file. Root has access to all files and folders and can make any edits.
Remember that only root or users with Sudo privileges can change permissions for files and folders.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to fix Linux related errors.

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/ibmimedia/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 to resolve 'ignore permission denied message from find' ?

To fix this error, apply the tip give below.

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 “ibmimedia”

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 Linux ?

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


How to 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 urgent assistance in Linux-related errors? – We're available to help you. ]


Conclusion

This article covers how to resolve the error 'ignore permission denied message from find' which occurs while running a 'find' command in Linux.
The find command is used to locate files on a Linux or Unix like operating system.
The find command will search directory to match the supplied search criteria.
You can search for files by type, name, owner, group, date, permissions and more. By default the find will search all subdirectories for you.

Linux divides the file permissions into read, write and execute denoted by r,w, and x.
The permissions on a file can be changed by 'chmod' command which can be further divided into Absolute and Symbolic mode.
The 'chown' command can change the ownership of a file/directory.

If you prefer using the command line, you can easily find a file's permission settings with the ls command, used to list information about files/directories.
You can also add the –l option to the command to see the information in the long list format.

To change directory permissions in Linux, use the following:
1. chmod +rwx filename to add permissions.
2. chmod -rwx directoryname to remove permissions.
3. chmod +x filename to allow executable permissions.
4. chmod -wx filename to take out write and executable permissions.