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

Re: keeping the two latest files on a folder



On Tue, Oct 13, 2009 at 12:24 PM, Israel Garcia <igalvarez@gmail.com> wrote:
> Hi List,
>
> It's a simple  question but difficult to me :-).
>
> How can I delete all files on a folder /xxxx but keeping only the two
> latest (newest)  files?

Here's one way, (warning: this will probably break painfully on
filenames with spaces in them),

ls --sort=time --time=ctime -1 | tail -n +3 | xargs rm -i

This is complicated enough logic that'd I'd write a one-off perl
script or shell function to do it, personally.

Mike


Reply to: