using perl to check modified date and then move to a folder

Posted on 2006-05-04
Last Modified: 2008-03-06
I am looking for a perl script that i can check the modfied date and then if its older than 6mos move into an archive folder.
Question by:nexcool
    LVL 4

    Expert Comment

    does it need to be perl ?
    a simple shell command would be more easy:

    find /dir/to/search -atime 180 -exec mv {}  /other/dir \;
    LVL 84

    Accepted Solution

    for( <*> ){
        rename $_,"/archive/$_" or warn "/archive/$_ $!" if -f && -M > 6*30;
    LVL 4

    Expert Comment

    or, if you want it recursive and with perl (re-using ozo's code),
    perl -MFile::Find -e 'find(sub {$_=$File::Find::name;rename $_,$ARGV[1].$_ or warn $ARGV[1]."$_ $!" if -f && -M > 6*30;},$ARGV[0])' /dir/to/search/ /dir/to/move/to/
    LVL 48

    Expert Comment


    -atime should be -mtime
    LVL 4

    Expert Comment


    Ah right, thanks =)

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
    Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now