[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: keeping the two latest files on a folder



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

--
Matthew Smith
Smiffytech - Technology Consulting & Web Application Development
Business:      http://www.smiffytech.com/
Blog/personal: http://www.smiffysplace.com/
LinkedIn:      http://www.linkedin.com/in/smiffy
Skype:         msmiffy
Twitter:       @smiffy


Reply to: