in reply to Deleting files over 2 weeks old?

I don't know if you're determined to use Perl or not to do this, but the Unix command 'find' will allow you to specify a number of days since create date or last access date. Pipe the output to 'xargs', and use 'rm'. Something like this:

find -ctime +14 | xargs -f rm

This should find all files created more than 14 days ago, and delete them. You could put this in a daily cron job, and it'll all happen for you.

Update: Don't do this! As merlyn points out in a following reply, this is a security risk. I'm a casual Unix user, and while I knew that filenames could contain odd characters, I didn't realize the implication of newlines in a file name. See below for more details.

--Chris

e-mail jcwren
  • Comment on (jcwren) RE: Deleting files over 2 weeks old?

Replies are listed 'Best First'.
(Ovid) RE(2): Deleting files over 2 weeks old?
by Ovid (Cardinal) on Aug 03, 2000 at 03:03 UTC
    As an amusing side note: a friend of mine worked for a large local ISP that shall remain nameless. They used the following as production code:
    cd /some/path/name find . -mtime +30 -print | xargs rm
    The problem, of course, is that this was run as root from the root directory. My friend got paged out of a movie when /some/path/name turned out to be invalid. You can imagine what happened :)

    The other problem (and I haven't tested this, to be honest) is that the above code will not get rid of filenames with spaces. Of course, that's pretty obscure, so I doubt it would come up.