Alan Fullmer
Super Administrator
       
Posts: 62
Registered: 8-12-2004
Member Is Offline
Mood: No Mood
|
posted on 15-2-2007 at 03:03 PM |
|
|
delete files by date with perl
This is a routine I use to sort through temp files in /tmp. It will delete all files older than 5 days. You can adjust this. I put it in a cron
entry to remove files that haven't gotten deleted from various web applications.
-M for modified
-C for created
| Quote: |
#!/usr/bin/perl
opendir(DELE, '/tmp') or die "Could not open directoryn";
print "directory openedn";
@TODELETE = readdir(DELE);
#PUT LOOP HERE
foreach $buh (@TODELETE)
{
if (-d $buh) {next}
if ((-M $buh) > 5)
{
unlink($buh);
print "removed $buhnn";
}
}
#END LOOP HERE
closedir(DELE);
|
|
|
|
Alan Fullmer
Super Administrator
       
Posts: 62
Registered: 8-12-2004
Member Is Offline
Mood: No Mood
|
posted on 20-6-2008 at 01:04 PM |
|
|
I may also add, there is a cron job that clears out files as well in /tmp.
|
|
|
Megane
Newbie
Posts: 1
Registered: 25-11-2009
Member Is Offline
|
posted on 25-11-2009 at 12:39 AM |
|
|
Thanks for the tips.I will try this..Cheers
Regards
Megane
Surendettement
|
|
|