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   [email protected]    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to