View Single Post

   
  #2 (permalink)  
Old 02-15-2008, 10:21 AM
Roger Cornelius
 
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.
>
> Can you help me ?


Here's one solution:

cd /whereever
n=5 # save $n most recent
set -- `/bin/ls -t`
if test $# -gt $n
then
shift $n
/bin/rm -f "$@"
fi
--
Roger Cornelius racpop@tenzing.org
Reply With Quote