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

Re: keeping the two latest files on a folder



On Tue, 13 Oct 2009, Israel Garcia 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?
>
how about something like this to start:
for file in $(ls -tA | egrep -v "$(ls -tA |head -n 2)") ; do if [ -f $file
] ; then echo "do a rm of $file"  ;fi ; done

-- 
8 out of 10 Owners who Expressed a Preference said Their Cats Preferred Techno.


Reply to: