Re: why is perl -e 'unlink(glob("*"))' so much faster than rm ?





xhoster@xxxxxxxxx wrote:
ewaguespack@xxxxxxxxx wrote:
i had a situation that required that i remove several thousand zero
byte files, and i tried this first:

# find . -type f -exec rm -f {} \;

this was taking ages, so on a hunch I decided to try this to see it I
got any better results:

That fires up a separate rm process for each file. Using strace -f, it
looks like this involves 99 system calls per rm (not counting the ones done
in the parent process), only one of which is related to the actual unlink.

# perl -e 'unlink(glob("*"))'

This doesn't do the -type f checking. If you don't really need to
do the -type f checking, why did you use find (rather than "rm -f *")
in the first place? One possible reason is if that gives you an argument
list too long error. I use the perl -le 'unlink(glob($ARGV[0]))' construct
frequently for just that reason.

surprisingly the perl unlink took about a quarter of a second to remove
1000 files versus 30 seconds with find / rm

That really surprises me. Not because of the difference between the two
methods, but because both of them are about 20 times slower for you than
they are on my not-particularly fast machine.

Xho

I used find because the original number of files would not delete using
rm -f *, i got the "argument list is too long" error

i think part of the problem is that the server in question was
experiencing high iowait times....

when I ran the rm command on an idle server it was much faster.

I am still curious why it was so much faster.

.



Relevant Pages

  • Re: why is perl -e unlink(glob("*")) so much faster than rm ?
    ... so on a hunch I decided to try this to see it I ... in the parent process), only one of which is related to the actual unlink. ... One possible reason is if that gives you an argument ... I use the perl -le 'unlink)' construct ...
    (comp.lang.perl.misc)
  • Re: Trying to do some signal handling ..
    ... The exit status is returned by waitin the parent process. ... > for some reason .. ... > int main ... > void dispDirFiles ...
    (comp.unix.programmer)