bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to avoid "Permission denied" when find some files


From: Bernhard Voelker
Subject: Re: How to avoid "Permission denied" when find some files
Date: Thu, 6 Aug 2020 00:07:12 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

On 2020-08-05 11:30, Bruce Wen wrote:
> Hi,
> 
> Sometimes, find command failed due to "Permission denied".
> 
> For example, the file owner is not me, and I have no read permission to the
> file, then "Permission denied" happened.
> 
> In this case, -readable and -perm cannot help. So, any way to avoid
> "Permission denied"?
> 
> Thanks!
> 
> Br,
> Bruce Wen

Unfortunately, you didn't give us the exact command to reproduce the problem.
So I assume you tried something like this:

  # Run as regular user, this would usually give "permission denied"
  # for e.g. '/root' and other files/directories like '/var/spool/cups'.
  $ find / -xdev -ls >/dev/null
  find: '/root': Permission denied
  ...

But the following works for me: pruning unreadable directories:

  $ find / -xdev -type d ! -readable -prune -o -ls >/dev/null
(no errors)

So the trick is not to continue when the current file/dir is readable
(because this is what find is doing anyway unless other negative test results
prevent this), but to stop processing the directory hierarchy when some 
directory
is not readable.

I suggest consulting the documentation for the -prune test.

FWIW there is currently a bug with the cost-based optimizer [1]
which lets other tests like -empty be performed before -readable even
if that test is specified later on the command line.
[1] https://lists.gnu.org/r/bug-findutils/2020-05/msg00008.html

Have a nice day,
Berny



reply via email to

[Prev in Thread] Current Thread [Next in Thread]