[H-GEN] chestnut
Greg Black
gjb at gbch.net
Wed Mar 26 20:03:20 EST 2003
[ Humbug *General* list - semi-serious discussions about Humbug and ]
[ Unix-related topics. Posts from non-subscribed addresses will vanish. ]
"Christopher Biggs" wrote:
> Sarah Hollings <sarah at humanfactors.uq.edu.au> [wrote]:
> >
> > Anyone know of a simple one-[or-two]-liner (in bash or perl -e) for
> > deleting the oldest file in a directory?
>
> $ rm -f 'ls -t | tail -1'
Interesting -- so far, we've had two answers and both of them
were wrong. Mine because I didn't read the question carefully
and gave an answer that deleted the newest file. This one
because it just has plain wrong syntax and won't delete any
files at all (unless you happen to have a file named with that
string between the single quotes).
The correct answer is, of course:
rm `ls -t | tail -1`
Note that those are backquotes, not single quotes.
For more modern shells, the safer syntax is:
rm $(ls -t | tail -1)
Greg
--
* 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