in reply to find "x" quantity newest files in a dir

perl -e '@sorted = sort { -M $a <=> -M $b } </path/*>; unlink foreach +@sorted[10..$#sorted]'

--
Snazzy tagline here

Replies are listed 'Best First'.
Re: Re: find "x" quantity newest files in a dir
by merlyn (Sage) on Jun 27, 2001 at 18:10 UTC
    You might find this rather expensive if you have 100 files or so, but if the directory is constantly being trimmed to 10 or 15 files, that's probably OK. Just in case someone copies your code for another task, it's nice to know how it scales.

    -- Randal L. Schwartz, Perl hacker

Re: Re: find "x" quantity newest files in a dir
by runrig (Abbot) on Jun 27, 2001 at 18:39 UTC
    unlink accepts a list, so you might say:
    unlink @sorted[10..$#sorted] if @sorted > 10;