Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cron script that will delete old files from a directory

Status
Not open for further replies.

pixelboi

Technical User
Feb 15, 2002
2
US
I need to write a cron job to run hourly that checks all files in a directory and deletes files that are older than 30 days.

id like it to also delete *.exe *.vbs *.bat type files as soon as it see them, any ideas? any help would be great, thanks!
 
here is a ksh script I use. the last entry just deletes .log file the other directories are all file extentions hth

#!/usr/bin/ksh
. ~/.profile
#
# This scripts is used to clean out any files over 7,14,30 and 60 days old in the tmp directory
#

find $HOME/tmp -name '*' -mtime +7 -exec \rm -f {} \; 1> /dev/null 2>&1
find $HOME/out -name '*' -mtime +14 -exec \rm -f {} \; 1> /dev/null 2>&1
find $HOME/data -name '*.*' -mtime +60 -exec \rm -f {} \; 1> /dev/null 2>&1
find $app -name '*.log' -mtime +14 -exec \rm -f {} \; 1> /dev/null 2>&1

exit
~
 
pay no attention to the bad comment in that script...

the tmp dir is cleaned out files 7 days old

out directory 14 days old

data directory 60 days old

and app dir .log files 14 days old
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top