Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How do I find and delete files based on age?

by talexb (Chancellor)
on Feb 27, 2007 at 04:22 UTC ( [id://602249]=note: print w/replies, xml ) Need Help??


in reply to How do I find and delete files based on age?

You're developing for Linux/Unix, right? I'm surprised that no one's mentioned tmpwatch yet. It's a tool that specifically written to get rid of files older than a particular age.

True, there's no Perl involved -- but sometimes the best answer is to not use Perl at all.

Update: .. And here's a link to the first page that Google found for tmpwatch. You can also find information about it by typing man tmpwatch on your Unix/Linux system.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Replies are listed 'Best First'.
Re^2: How do I find and delete files based on age?
by Anonymous Monk on Feb 28, 2007 at 00:22 UTC
    WARNING: The following text is much like the ramblings of an old man, etc ...

    Ahhh ... the ol' "remove old files" script. Had to do a few of these,
    over the years, at numerous companies. It is usually as a result of the
    file system filling up with "old" log files, etc (eg log001, log002, etc).

    The easiest thing to do back then was to run the one-liner Unix "find" command
    with the "-mtime" followed by the "-exec" or "-delete" flag
    (see http://unixhelp.ed.ac.uk/CGI/man-cgi?find). Just an option to consider ...

    ... Anyway the important thing here, however, was that in the early days I made a complete mess
    of things when I didn't TEST the script first.

    Nowadays I have a scheduled task that archives/zips the old (1 week) files
    to another directory (much like a trashcan). Another task removes or deletes
    these files from the archived directory sometime later (if they are 2 or
    more weeks old). Of course, you can manually delete the files at any time
    knowing that they have been backed-up on tape by the system administrators - right?

    Some tips (hopefully it's not too late ...)
    In your script (perl or otherwise):

    * Have an option to only display the files to be deleted - or to display before deletion (with a confirmation)

    * Have an option to archive rather than delete old files (eg move to another directory and gzip)

    * Have an option to "restore" files from the archive (ie an "undelete")

    * As you become more confident, allow handling of files via "regular expression" - handly for file names containing unsual characters or spaces, etc.

    * Perhaps you can consider searching for files based on file attributes such as file sizes and (modified) dates (use ranges) and file types

    * Log what has been archived (or restored) or deleted, the time and the *user id*

    * If this is your first script - ever - and you are basically performing a "rm *.* www.*" then for goodness sake do not put your name on the script!

    - Laz.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://602249]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2024-04-25 18:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found