http://qs321.pair.com?node_id=28914


in reply to Find files older than x days and delete them

Here is a script I have used for a similar task in one directory. I have changed the name of the directory for obvious reasons:
#! /usr/local/bin/perl die unless chdir "/some/hardcoded/dir/here"; die unless opendir DIR, "."; foreach $file (grep {-f && (14 < -M)} readdir DIR) { unlink $file; } closedir DIR;
Amusing note. I wrote this after accidentally crashing someone else's ftp server by throwing the accumulated contents of a large dir at it. The next day I went and made every change I could think of that would have prevented the disaster. Running this script daily was one of those changes. :-)

EDIT
Hmmm...this was one of my earlier scripts. Definitely before I learned the value of informative error messages. And written in a hurry...but I think I should leave it anyways as an example to show that my coding style has matured...