Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Perl / Modules / July 2009



Tip: Looking for answers? Try searching our database.

module/script to clean up old files and prune empty directories

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jonathan Swartz - 01 Jul 2009 00:59 GMT
At various places around our system we want to clean up files older  
than x, and sometimes prune empty directories. Naturally we have to be  
careful doing this lest we accidentally blow away far too many of the  
wrong files.

I'm thinking about a Perl module and accompanying script with this  
interface:

    cleanup_files.pl  --age=age --dir=dir --name=name [--dry-run] [--
prune-empty-dirs]

where age can be specified as "1h", "2day", etc., and name is a  
required glob pattern, and dir is checked to make sure it is  
sufficiently deep (e.g. can't use /). --dry-run tells you what would  
be deleted. --prune-empty-dirs also causes empty dirs to be pruned.  
The script would report at its end how many files and directories were  
removed.

The idea is to have a convenient, but safe, one-liner to put in a cron  
for each directory that needs periodic cleaning.

In the past we've done the old "find ... | xargs rm -f", but it  
doesn't have the safety checks, directory pruning, or reporting.

Does anyone else think this is (mildly) valuable? Am I reinventing the  
wheel, in terms of Perl libraries or other Unix utilities besides  
basic find?

Thanks
Jon
Bill Ward - 01 Jul 2009 01:09 GMT
I want it, whether it is already extant or you write it...

> At various places around our system we want to clean up files older than x,
> and sometimes prune empty directories. Naturally we have to be careful doing
[quoted text clipped - 24 lines]
> Thanks
> Jon

Signature

Check out my LEGO blog at http://www.brickpile.com/
View my photos at http://flickr.com/photos/billward/
Follow me at http://twitter.com/williamward

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.