Dir::Purge
20 February 2004 02:00
Found a very useful Perl Module today. It's a bit old, but useful nonetheless. Here's the situation: In making backups of certain things I find myself wanting to be able to keep around the N newest files in a certain directory. A simplistic way of doing this is something like
find . -mtime +N -exec rm {} ;
Or something like that. The problem with that is that if, for some reason you fail to make a backup for some number of days, you eventually lose all your backups. So I found Dir::Purge on CPAN which does things a little smarter. It lets you specify how many files you want to keep around, and it's smart enough to keep the N newest (or oldest) files around. Nice. Makes my job easier, and it's code I don't have to maintain. Even better.
So my co-worker also offers a similar 1-liner solution by using a combination of ls -latr, and head or tail. Yeah, that'd probably work too :-).
Comments
|