unix move files based on date range

Posted on 2009-12-17
Last Modified: 2013-12-26
  What command should i use to move a large set of files in a directory to another directory based on the last modified date range?

ex: move files with last modified date from 9/01/09 to 10/01/09.

Question by:jennyvo22
    LVL 40

    Expert Comment

    try with the find command with the option -mtime n where n is number of days and can be positive or negative value
    LVL 68

    Accepted Solution

    You can get a very fine-grain selection (even including hours/minutes/seconds, if needed) with this method
    touch -t 200909010000.00 /tmp/datefrom
    touch -t 200910010000.00 /tmp/dateto
    find /source/directory -type f -newer /tmp/datefrom ! -newer /tmp/dateto -exec mv {} /target/directory \;
    rm /tmp/datefrom /tmp/dateto
    The format ot the -t parameter of touch is with the .ss part being optional.
    LVL 7

    Assisted Solution

    woolmilkporc 's solution is nice. However, it has a drawback which can easily be repaired

    For a bulk operation of really many files it is extremely inefficient, since it forks a new mv process for each single file.


    find /source/directory -type f -newer /tmp/datefrom ! -newer /tmp/dateto -print0|xargs -r --null mv --target-directory=/target/directory \;

    instead of woolmilkporc's find


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Article by: IanTh
    Hi Guys After a whole weekend getting wake on lan over the internet working, I thought I would share the experience. Your firewall has to have a port forward for port 9 udp to your local broadcast x.x.x.255 but if that doesnt work, do it to a …
    This is an article about my experiences with remote access to my clients (so that I may serve them) and eventually to my home office system via Radmin Remote Control. I have been using remote access for over 10 years and have been improving my metho…
    After creating this article (, I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    760 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

    8 Experts available now in Live!

    Get 1:1 Help Now