Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

removing old dirs

by swaroop (Beadle)
on Feb 27, 2006 at 06:31 UTC ( [id://532969]=perlquestion: print w/replies, xml ) Need Help??

swaroop has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: removing old dirs
by PodMaster (Abbot) on Feb 27, 2006 at 07:06 UTC
Re: removing old dirs
by mickeyn (Priest) on Feb 27, 2006 at 07:26 UTC
    since this is a rather simple 'find' task, you can use 'find2perl' to get your code:

    find2perl -type d -mtime +7

    and the output will be ....

    Of course, you can modify the sub 'wanted' as you like ...

    Enjoy,
    Mickey

Re: removing old dirs
by ambrus (Abbot) on Feb 27, 2006 at 20:04 UTC

    I have the following command in an init-script on my machine.

    This removes both directories and files older than 1 day from the /tmp directory.

    There's one problem with this code, namely that when it removes a file or subdirectory from a directory, the mtime of the directory would change, so it doesn't get deleted anymore even if it was old before this. So, such directories would disappear only after multiple iterations of this code. This is no problem, as deep directory structures aren't really common in /tmp, don't take up much space anyway, and it's not a great problem that these are deleted only after multiple reboots. (What causes more problems are in fact temporary files that are not in /tmp but somewhere else.)

    perl -we 'use File::Find; finddepth(sub { 1 < -M() and -d() ? rmdir : +unlink; }, "/tmp")'

    The usual disclaimers apply: use only for your own responsability.

    Update: see also Automatically Deleting Files Periodically.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-23 08:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found