keep find from trying to spider directories where it has no permission

View: New views
8 Messages — Rating Filter:   Alert me  

keep find from trying to spider directories where it has no permission

by jidanni :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It seems there is no way to tell find to look before it leaps,

$ find /tmp -user $LOGNAME -type f -mtime +1 -exec rm {} \;
find: /tmp/mc-jidanni3: Permission denied
$ find /tmp -depth -user $LOGNAME -type d -empty -mtime +1 -exec rmdir {} \;
find: /tmp/mc-jidanni3: Permission denied

Is there any gentler way, or must one resort to 2>/dev/null ?



Re: keep find from trying to spider directories where it has no permission

by Eric Blake :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to jidanni@... on 9/15/2009 5:16 PM:
> It seems there is no way to tell find to look before it leaps,
>
> $ find /tmp -user $LOGNAME -type f -mtime +1 -exec rm {} \;

Have you looked at using -ok instead of -exec?

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@...
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkq1AIYACgkQ84KuGfSFAYBVqwCghwhrQGM2jF1YtJjLZSeHHI3c
omsAoJbk1fW9ldPF68kK5idzVC1sZEZ5
=yMpt
-----END PGP SIGNATURE-----



Re: keep find from trying to spider directories where it has no permission

by jidanni :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>> It seems there is no way to tell find to look before it leaps,
>>
>> $ find /tmp -user $LOGNAME -type f -mtime +1 -exec rm {} \;

EB> Have you looked at using -ok instead of -exec?

It's a total batch job, -ok not OK, OK?

I'm trying to tell find:
do what you need to do, but if you encounter any closed doors, don't
rattle them (simple salesman etiquette), just go on to the next.

I could use 2>&-, but I still want to see any problems.

So it's a general
       find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]
case, but with an added feature,
-ignore-unreadable-directories
that I think I want... you to add to find's functionality.



Re: keep find from trying to spider directories where it has no permission

by Eric Blake :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to jidanni@... on 9/19/2009 10:16 AM:
> So it's a general
>        find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]
> case, but with an added feature,
> -ignore-unreadable-directories

Find can already do that without the need for an additional option.  You
just have to specify the right predicates.

Untested, but:

- -type d \! -readable -prune

seems like it should do the trick of telling find to not descend into
unreadable directories.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@...
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkq1BeIACgkQ84KuGfSFAYAWBgCfdJ24TtXM7i+ijd7vBAWvjGAv
UlEAoKkKWbJDxUvuXezoyhML87JKYEVr
=Dryz
-----END PGP SIGNATURE-----



Re: keep find from trying to spider directories where it has no permission

by jidanni :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

EB> Untested, but:
EB> -type d \! -readable -prune
EB> seems like it should do the trick of telling find to not descend into
EB> unreadable directories.

Well, I hope there can be an example added to the find man page.

Anyway, in the general case ... there needs to be a way...

$ chmod 0 jidanni.org/geo/islands
$ find jidanni.org -type f|wc
find: `jidanni.org/geo/islands': Permission denied
    419     419   17983
$ find jidanni.org ! -readable -prune -type f|wc
      0       0       0

Anyway, the challenge is to get the same output as
$ find jidanni.org -type f 2>&-|wc
    419     419   17983
without the 2>&- .



Re: keep find from trying to spider directories where it has no permission

by James Youngman-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, Sep 19, 2009 at 4:41 PM,  <jidanni@...> wrote:

> EB> Untested, but:
> EB> -type d \! -readable -prune
> EB> seems like it should do the trick of telling find to not descend into
> EB> unreadable directories.
>
> Well, I hope there can be an example added to the find man page.
>
> Anyway, in the general case ... there needs to be a way...
>
> $ chmod 0 jidanni.org/geo/islands
> $ find jidanni.org -type f|wc
> find: `jidanni.org/geo/islands': Permission denied
>    419     419   17983
> $ find jidanni.org ! -readable -prune -type f|wc
>      0       0       0
>
> Anyway, the challenge is to get the same output as
> $ find jidanni.org -type f 2>&-|wc
>    419     419   17983
> without the 2>&- .

~/tmp$ find . \! -readable -prune , -type f | wc
      2       2      36
~/tmp$ find . -type f | wc
find: `./unr': Permission denied
      2       2      36



Re: keep find from trying to spider directories where it has no permission

by Jim Meyering :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

James Youngman wrote:

> On Sat, Sep 19, 2009 at 4:41 PM,  <jidanni@...> wrote:
>> EB> Untested, but:
>> EB> -type d \! -readable -prune
>> EB> seems like it should do the trick of telling find to not descend into
>> EB> unreadable directories.
>>
>> Well, I hope there can be an example added to the find man page.
>>
>> Anyway, in the general case ... there needs to be a way...
>>
>> $ chmod 0 jidanni.org/geo/islands
>> $ find jidanni.org -type f|wc
>> find: `jidanni.org/geo/islands': Permission denied
>>    419     419   17983
>> $ find jidanni.org ! -readable -prune -type f|wc
>>      0       0       0
>>
>> Anyway, the challenge is to get the same output as
>> $ find jidanni.org -type f 2>&-|wc
>>    419     419   17983
>> without the 2>&- .
>
> ~/tmp$ find . \! -readable -prune , -type f | wc
>       2       2      36
> ~/tmp$ find . -type f | wc
> find: `./unr': Permission denied
>       2       2      36

Nice example.  I had to look up the "," operator.



Re: keep find from trying to spider directories where it has no permission

by jidanni :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>>>>> "JM" == Jim Meyering <jim@...> writes:
JM> James Youngman wrote:
>> On Sat, Sep 19, 2009 at 4:41 PM,  <jidanni@...> wrote:
EB> Untested, but:
EB> -type d \! -readable -prune
EB> seems like it should do the trick of telling find to not descend into
EB> unreadable directories.

>>>
>>> Well, I hope there can be an example added to the find man page.
>>>
>>> Anyway, in the general case ... there needs to be a way...
>>>
>>> $ chmod 0 jidanni.org/geo/islands
>>> $ find jidanni.org -type f|wc
>>> find: `jidanni.org/geo/islands': Permission denied
>>>    419     419   17983
>>> $ find jidanni.org ! -readable -prune -type f|wc
>>>      0       0       0
>>>
>>> Anyway, the challenge is to get the same output as
>>> $ find jidanni.org -type f 2>&-|wc
>>>    419     419   17983
>>> without the 2>&- .
>>
>> ~/tmp$ find . \! -readable -prune , -type f | wc
>> 2       2      36
>> ~/tmp$ find . -type f | wc
>> find: `./unr': Permission denied
>> 2       2      36

JM> Nice example.  I had to look up the "," operator.
OK, it works. Please add such an example to the man page. Thanks.