View Single Post

   
  #3 (permalink)  
Old 02-15-2008, 10:21 AM
Richard Howlett
 
Posts: n/a
Default Re: How to keep only 5 most recent files in certain folder

Sinisa wrote:
> Hi,
>
> I am trying to make a script that would run every couple hours and purge all
> files in certain folder except last five files (most recent).
> Files are being added to that folder constantly.


Adapted from the standard way in .procmailrc to keep the latest n files in a
backup directory where n is 5 to satisfy your criteria:

rm -f dummy `ls -t |sed -e 1,5d`

The reference to dummy is to ensure rm always has at least one filename as a
parameter.

--
Richard Howlett
newsgroups@howie.org.uk
Mail to "newsgroups" will be rejected.
Mail to my forename will not.

Reply With Quote