Xnote.com Technical Forums Last active: Never
Not logged in [Login - Register]
Go To Bottom

Printable Version | Subscribe | Add to Favourites  
Author: Subject: delete files by date with perl
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);




View User's Profile Visit User's Homepage View All Posts By User U2U Member
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.



View User's Profile Visit User's Homepage View All Posts By User U2U Member
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
View User's Profile View All Posts By User U2U Member


Go To Top


Powered by XMB
Developed By Aventure Media & The XMB Group © 2002-2007