#!/bin/ksh # This script prunes the specified directory # by removing all files except for the last cnt files # # Usage: # prune-directory.scr dir 'file-list' cnt # # Example: prune-directory.scr dir '*.gif' 100 # # this will prune the *.gif files in dir/ # ############################## cnt=$3 flist=${1}/$2 echo PRUNE LOG 1> ./prune.sst.log 2>&1 ls -1r $flist | while read f; do if [[ $cnt -gt 0 ]]; then cnt=$((cnt-1)) else echo rm $f 1>> ./prune.sst.log 2>&1 rm $f fi done