[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:36:52 -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 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.

You will not get the error if you tell find to do a depth-first search:

find . -depth -name a -exec rm -rf {} \;

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

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]