#!/bin/bash
#checks for the number of files in /dump directory with the prefix passed as first parameter
#retains the latest number of files(indicated by second parameter) 
cd /dump

files=`find -name "$1*" | cut -d "/" -f2 | wc -l`
nf=`expr $2 - 1`
if [ $files -gt $nf ]
then 
   for i in `ls -trx $1*`
   do 
    if [ $files -gt $nf ]
    then
       rm -f $i
    fi
    (( files = $files-1 ))
   done
fi
