[Top][All Lists]

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

Re: find acting weird

From: Юрий Пухальский
Subject: Re: find acting weird
Date: Wed, 26 May 2010 19:53:47 +0400

2010/5/26 Eric Blake <address@hidden>:
> On 05/26/2010 03:42 AM, Юрий Пухальский wrote:
>> Good day!
>> I'm trying to remove the directories with find -exec and i've
>> encountered that for some reason the behaviour is strange. I've tested
>> with 4.1.20, 4.2.27 and 4.4.2.
>> I'm doing the following:
>> devfe:~>mkdir -p findtest/a/b
>> devfe:~>cd findtest/
>> devfe:~/findtest>find . -name a -exec rm -rf {} \;
>> find: ./a: No such file or directory
>> devfe:~/findtest>ls
>> devfe:~/findtest>
> Interesting example of concurrent modification.  By default, find does
> recursion breadth-first - it builds the list of all candidates in the
> current directory, then tries to descend into that list.  But you
> deleted a in between those two steps.

    The primary shall always evaluate as true; it shall cause descent
of the directory hierarchy to be done so that all entries in a
directory are acted on before the directory itself. If a -depth
primary is not specified, all entries in a directory shall be acted on
after the directory itself. If any -depth primary is specified, it
shall apply to the entire expression even if the -depth primary would
not normally be evaluated.

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 {} \;

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.

> 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.

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

«The good thing about standards is there are so many to choose from.»

reply via email to

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