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



ewaguespack@xxxxxxxxx writes:

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:

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

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

any idea why?

The find was spawning a new instance of 'rm' for each file - very inefficient.

The equivalent to your Perl code would be to use find to get a list of files,
and then use 'xargs' to pass that whole list to one instance of 'rm':

find . -type f -print0 | xargs -0 rm -f

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
.



Relevant Pages

  • Re: Blank lines and paragraph break in html
    ... If you use something reasonably modern - Perl, Ruby, Python, Java, ... Total overkill. ... Web Hosting by West Virginians, ...
    (comp.infosystems.www.authoring.html)
  • Re: RubyCocoa Sheets - help anyone?
    ... Web Hosting by West Virginians, ... Cocoa programming in Perl: http://camelbones.sourceforge.net ...
    (comp.lang.ruby)
  • Re: finding perl info on google can be hard
    ... are nonsensical regardless of the file size, but doesn't do a bounds check ... | written into the gap). ... So Perl is just reporting what the OS does. ... Web Hosting by West Virginians, ...
    (comp.lang.perl.misc)
  • Re: Where did cgi-bin go?
    ... After all, some sites like slashdot ... Web Hosting by West Virginians, ... Cocoa programming in Perl: http://camelbones.sourceforge.net ...
    (comp.lang.perl.misc)
  • Re: Blank lines and paragraph break in html
    ... Just regex pairs of adjacent linebreaks into. ... If you use something reasonably modern - Perl, Ruby, Python, Java, ... Web Hosting by West Virginians, ...
    (comp.infosystems.www.authoring.html)