Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Deleting old files
Name: duffster Date: February 21, 2003 at 00:41:22 Pacific OS: AIX 4.3.3 CPU/Ram: na
Comment:
I am writing a script which will run every 15mins and need to delete files from a given directory which are over n number of mins old. Any Ideas??
In the script: - check for the 'test' file --> exit if not there - loop through the files - Check if they are older that the 'test' file - Remove them if they are. - Create/update timestamp of the 'test' file - exit
The first time the script runs nothing should happen because the 'test' file does not yet exist.
Here is my attempt: #! /bin/ksh PATH=/path/to/your/dir/ TEST="${PATH}test_file" [[ ! -f $TEST ]] && exit 1
for i in `find $PATH -type f` ; do [[ $i = $TEST ]] && continue [[ $i -ot $TEST ]] && rm -r $i done
touch test_file
-jim
0
Response Number 2
Name: Jimbo Date: February 21, 2003 at 03:45:04 Pacific
Reply:
Ohh,
the script should be run from cron at the interval in minutes you are looking for old files.
i.e. if you want to remove files that are older that 30 minutes old, run the script every 30 minutes.
-jim
0
Response Number 3
Name: duffster Date: February 24, 2003 at 06:32:26 Pacific
Summary: I need a ftp script to delete old text files on a remote server based on the file retention rules such as 2 weeks, 1 month, etc. It can be written as a Korn script or Perl. Thanks for your help. ...
Summary: Please help... I need to delete files in all sub-directories that are more than 10 days old or delete all sub-directoires (entire directory) that's 10 days old (this is risky). I have an archive direc...