?
Solved

unix move files based on date range

Posted on 2009-12-17
3
Medium Priority
?
733 Views
Last Modified: 2013-12-26
Hi,
  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.

Thanks!
0
Comment
Question by:jennyvo22
3 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 26070061
try with the find command with the option -mtime n where n is number of days and can be positive or negative value

http://unixhelp.ed.ac.uk/CGI/man-cgi?find
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 26072426
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 YYYYMMDDhhmm.ss with the .ss part being optional.
wmp
0
 
LVL 7

Assisted Solution

by:hemmi
hemmi earned 500 total points
ID: 26072707
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.

use

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

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re involved with your company’s wide area network (WAN), you’ve probably heard about SD-WANs. They’re the “boy wonder” of networking, ostensibly allowing companies to replace expensive MPLS lines with low-cost Internet access. But, are they …
During and after that shift to cloud, one area that still poses a struggle for many organizations is what to do with their department file shares.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), 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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

750 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