Sharing a shell script that delete all files in a particular dir that match a pattern. The same can also be achieved by a combination of find and rm commands. This script can be called from a master script that is responsible for cleaning up temp or intermediate files generated by application. It emails list of all files deleted and user who invoked the script ;).
#!/usr/bin/ksh # Pass directory path and pattern as arguments DIR=$1 PATTERN=$2 cd $DIR USER=`whoami` SUMMARY=`printf "User: $USER\nDIR: $DIR\nPattern: $PATTERN\nFiles Deleted:-"` for i in `ls $PATTERN` do SUMMARY=`printf "$SUMMARY\n$i"` rm -f $i done printf "$SUMMARY" | mailx -s "Files Clean Up" email@example.com