[H-GEN] chestnut
Jason Parker-Burlingham
jasonp at uq.net.au
Wed Mar 26 23:09:15 EST 2003
[ Humbug *General* list - semi-serious discussions about Humbug and ]
[ Unix-related topics. Posts from non-subscribed addresses will vanish. ]
Greg Black <gjb at gbch.net> writes:
> [ Humbug *General* list - semi-serious discussions about Humbug and ]
> [ Unix-related topics. Posts from non-subscribed addresses will vanish. ]
>
> Sarah Hollings wrote:
>
> > Anyone know of a simple one-[or-two]-liner (in bash or perl -e) for
> > deleting the oldest file in a directory?
>
> This one will work in /bin/sh or any Bourne-style shell:
>
> rm `ls -tr | tail -1`
The equivalent Perl isn't quite as succinct or clear, I'm afraid:
unlink (sort {
(stat $a)[10] <=> (stat $b)[10]
} grep {
-f
} glob q/*/)[0]
I'm sure there's a better way using some module or other, but, eh.
(Also I think Greg's code needs a little grepping to discount
directories unless failure is okay.)
--
uck Wa!
--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'. See http://www.humbug.org.au/
More information about the General
mailing list