[CentOS] [Fwd: Re: The directory that I am trying to clean up is huge]

Mon Jan 25 15:33:43 UTC 2010
Robert Nichols <rnicholsNOSPAM at comcast.net>

James B. Byrne wrote:
 > On Sat, January 23, 2010 20:21, Robert Nichols wrote:
 >> Robert Heller wrote:
 >> Gosh, then I guess the manpage for 'find' must be totally wrong
 >> where it
 >> says:
 >>         -exec command ;
 >>                ...
 >>                The specified command is run once for each matched
 >> file.
 > Not wrong.  The man page on find simply does not speak to the limits
 > of the kernal configuration (MAX_ARG_PAGES) implicitly used by cp,
 > find, ls, etc.  It just lives within its means and fails when these
 > do not suffice.
 > The problem you have is that the selection of all qualified files is
 > completed before any are acted on by find.  So, in the case of
 > overlarge collections, the page limit is exceeded before any are
 > deleted.  Taking each file as it is found and piping it to an
 > external rm command avoids hitting the page limit.

When using the -exec action with the ";" terminator, the constructed
command line always contains the path for exactly one matched file.
Try it.  Run "find /usr -exec echo {} ;" and see that you get one
path per line and output begins almost instantly.  Do you really
believe that 'find' searched the entire /usr tree in that time?

Now if the "{}" string appears more than once then the command line
contains that path more than once, but it is essentially impossible
to exceed the kernel's MAX_ARG_PAGES this way.

The only issue with using "-exec command {} ;" for a huge number of
files is one of performance.  If there are 100,000 matched files,
the command will be invoked 100,000 times.

Bob Nichols     "NOSPAM" is really part of my email address.
                 Do NOT delete it.