bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: findutils 4.1.7


From: Bob Proulx
Subject: Re: findutils 4.1.7
Date: Mon, 29 Dec 2003 08:43:50 -0700
User-agent: Mutt/1.3.28i

khamis Siksek wrote:
> this is related to find utility when used with -exec and rm
> 
> when executing "find PATH SOMETHING -exec rm -rf {} \;" it gives error
> that it cannot find SOMETHING, although it deletes SOMETHING and so it
> is normal that it cannot find it.

I could not recreate a problem using PATH and SOMETHING when SOMETHING
was outside of the first path.  However, if SOMETHING was a
subdirectory of PATH then of course you will cause the error message.
But of course that is expected in that case.

I don't think this can really be said to be a problem with find.  You
are running an external command and it is modifying the directory
structure out from underneath the running find while find is running.
The find command knows nothing about 'rm' and does not know that you
are deleting directories.  You can run any command by -exec.

Also, the combination of 'rm -rf' coupled with 'find' is a strange
one.  Both commands are doing directory traversal.  As they say, the
man with two watches never knows exactly what is the time.  Pick only
one command at a time to do directory traversal.  For your specific
example only the rm -rf was needed and the find was completely
superfluous.  In a different example I would suggest only using the
'find' with 'rm -f' and not using the rm directory traversal.

In many systems starting a separate process for every file, such as
done in your example using -exec, can be very inefficient.  The find
and xargs commands are designed to avoid that inefficiency.  If using
the GNU software you can use '-print0 | xargs -r0' to group arguments
into bigger bundles of program executions.  Such as in your example
modified for xargs.  (I hate using rm as an example, the echo makes it
safe.  Remove the echo after verifying the command.)

  find PATH SOMETHING -print0 | xargs -r0 echo rm -f

Bob




reply via email to

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