[Top][All Lists]

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

Re: find acting weird

From: Eric Blake
Subject: Re: find acting weird
Date: Wed, 26 May 2010 09:58:11 -0600
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20100430 Fedora/3.0.4-3.fc13 Lightning/1.0b1 Mnenhy/0.8.2 Thunderbird/3.0.4

On 05/26/2010 09:53 AM, Юрий Пухальский wrote:
> So goes the standard. It's not clear (for me) what means "all entries
> in a directory". In this case it depends on whether we consider it
> before or after -exec.
>> You will not get the error if you tell find to do a depth-first search:
>> find . -depth -name a -exec rm -rf {} \;
> Yes, or using the + works. But the question is whether this behaviour
> is correct. I've tried it on HP-UX:
> mk2HPX04:/build/mk2HPX04/tmp>mkdir -p a/b
> mk2HPX04:/build/mk2HPX04/tmp>find . -name a -exec rm -rf {} \;
> mk2HPX04:/build/mk2HPX04/tmp>

Bug in HP-UX - they are not detecting a valid error case of the
directory disappearing out from underneath the two-stage traversal, due
to the -exec action.

> and on AIX:
> mk2AIX03:/build/mk2AIX03/tmp>mkdir -p a/b
> mk2AIX03:/build/mk2AIX03/tmp>find . -name a -exec rm -rf {} \;
> find: 0652-081 cannot change directory to </build/mk2AIX03/tmp/a>:
>   : A file or directory in the path name does not exist.
> mk2AIX03:/build/mk2AIX03/tmp>

Same behavior as GNU findutils, as required by POSIX.

>> For that matter, maybe you would be more interested in directly using
>> find's -delete action, rather than exec'ing external processes - this is
>> more efficient:
>> find \( -name a -o -path '*/a/*' \) -delete
> Alas, it's not standard.

Indeed, but you didn't make it clear up front whether you were
interested in standards or in extensions.  Meanwhile, using Dmitry's
suggestion of using -prune is standard.

Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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