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

This node falls below the community's minimum standard of quality and will not be displayed.

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.