Matthew Smith skrev:
Quoth Håkon Alstadheim at 14/10/09 16:37...
Due to all the positive feed-back, I actually tested the "ls
-rt"-bit, and sure enough, the 'r' makes ls list the newest files
_last_, so you DON'T want 'r'. This makes the correct command:
rm $(ls -t | sed '1,2d')
I thought this looked like an interesting recipe, so I tried it.
(With echo, I hasten to add.)
I get a listing of every file (and directory) in the directory, but
all on one line.
All the sed seems to do is to convert the multiple spaces used to
format ls -t into single spaces.
Cheers
M
Test-run:
--------
$ mkdir tull
$ cd tull
$ touch a b c d
$ ls -l
totalt 0
-rw-r--r-- 1 hakon hakon 0 2009-10-14 08:18 a
-rw-r--r-- 1 hakon hakon 0 2009-10-14 08:18 b
-rw-r--r-- 1 hakon hakon 0 2009-10-14 08:18 c
-rw-r--r-- 1 hakon hakon 0 2009-10-14 08:18 d
$ ls | sed '1,2d'
c
d
---------
Seems to work here. Standard behaviour for 'ls' is to use
single-column-mode when output is not to a tty. Your ls command may be
aliased to something, or it might be a different version from mine. Try
the manual page. Try with the '-1' option to force single-column-mode.
--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org