≡ Menu

Linux / Unix Find Command: Avoid Permission Denied Messages

When I type find . -type d -name "foo" command I get Permission denied error messages. How do I exclude all “permission denied: messages from the find command under Linux or Unix like operating systems?

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.

Find command basic syntax

The syntax is:

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 /tmp -iname "data*.txt"


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

Sample outputs:

Fig. 01:  Find will show an error message for each directory on which you don't have read permission.

Fig. 01: Find will show an error message for each directory on which you don’t have read permission.

In this above example, I do not have read permission for vmware-root and orbit-Debian-gdm directories. To to avoid this problem try the following syntax:

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

Sample outputs without permission denied spam from find command:


How does it works?

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

 ## redirect error spam to /dev/null ##
find . -iname "data*.txt" -print 2>/dev/null > output.txt
cat output.txt
See also
  • Man page for bash or ksh shell.
Share this tutorial on:

Like this? Follow us on Twitter OR support us by using Patreon

{ 1 comment… add one }
  • Madan December 16, 2014, 10:09 am

    Both errors and warning are thrown into stderr is there any way we can identify that the command has a warning in it and not the error ??
    Apart from checking the return code !!

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , , , ,