Portal Home > Knowledgebase > Articles Database > [Help] Cron to delete aged files?


[Help] Cron to delete aged files?




Posted by kohkindachi, 01-08-2010, 10:04 PM
I'm looking for a cron to automatically delete files which is like 3 hours after last modified, excluding htaccess and index.php. any help?

Posted by activelobby4u, 01-09-2010, 03:20 AM
are the files randomly generated ? . In case of which you can have more effective solutions.

Posted by Dr:linux, 01-10-2010, 04:50 AM
Setting cronjob is the best option in Linux commands. Using shell scripts can make more damage and would erase your entire file system. find /yourdir/tmp -mtime -exec rm {} \; Filemtime shows you the modified time and unlink the ones that are older than 3 hours using date,month or anything else. Just use ls -l instead of rm to check whether the correct files are getting deleted.

Posted by LeaTrueman, 01-10-2010, 07:11 AM
try using -mmin instead of -mtime.

Posted by mattle, 01-11-2010, 12:45 PM
I'd opt for something a little more sophisticated so that you don't blow away important files: (untested) Or, you may want to filter the files earlier:



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
Suhosin help please (Views: 639)
gowebman.com down (Views: 617)