r6748 - in branches/gcc4/BOOK: chapter01 chapter05

Jeremy Huntwork jhuntwork at linuxfromscratch.org
Wed Aug 31 11:27:12 PDT 2005

On Wed, Aug 31, 2005 at 07:11:48PM +0100, Matthew Burgess wrote:
> >find ${GCC_INCLUDEDIR}/* -maxdepth 1 -xtype d -exec rm -rf {} \; &&
> >
> >That way, `find' only ever points to (and scans as far as) the top-level 
> >directories that need deleting, therefore can't race with `rm' which 
> >recursively deletes below those directories.
> Can anyone comment on my above suggestion?  Will it avoid the race 
> condition?  Looking at find(1L) hints that '-maxdepth 0' is actually 

linux1:jeremy ~ $ mkdir -p test/{dir1,dir2,dir3}
linux1:jeremy ~ $ touch test/file
linux1:jeremy ~ $ mkdir -p test/dir1/dir1A
linux1:jeremy ~ $
linux1:jeremy ~ $ find test/* -xtype d
linux1:jeremy ~ $ find test/* -xtype d -maxdepth 0

>From 'man find':
"       -exec command ;
              Execute  command;  true if 0 status is returned."

So, find would execute rm -rf on anything returned as 0, or found. As
you can see from the above example, the -maxdepth 0 effectively returns
only the top directories in the path specified. That should remove any
race conditions.

find ${GCC_INCLUDEDIR}/* -maxdepth 0 -xtype d -exec rm -rf () \;

should work.


More information about the lfs-book mailing list