Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move files between dates

Status
Not open for further replies.

spookie

Programmer
May 30, 2001
655
IN
Hi,
How can i move files between specific dates ?

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Please explain more.

Or do you mean how to change the modify-date of a file? See "man touch".



HTH,

p5wizard
 
Hi p5wizard,
I am having certain files starting from 10-Apr-2007 till date. I have to move files having modification date till 1-may-2007 to move to archive folder.
How can i acheive this besides using
Code:
mv file1 file2 ... /archive

Thanks in advance.

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Hmmm, tricky. It is much easier to move files between specific filesystems! (Sorry, I just couldn't resist that comment)

Here's a (better) thought:
'touch -t' a file (FILE-A) with one date (& time) and produce a list of files newer/younger than it. (see man find) then 'touch -t a file (FILE-B) with another date (& time) and remove from your list any files newer/younger than this. The resulting list of files should be those between the dates of FILE-A and FILE-B.

A second idea:
Convert the dates to 'number of days ago' and use the find -mtime with plus (+) and minus (-) values.

I hope that helps.

Mike

 
Convert the dates to 'number of days ago' and use the find -mtime with plus (+) and minus (-) values.
Sorry mike, but can you elaborate on this more?

Thanks



--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
If today is 08-May-2007, then 10-Apr-2007 was 28 days ago and 01-May-2007 was 7 days ago. Using 'find' look for files that younger than 28 days (-mtime -28) and are older than 7 days (-mtime +7).

I hope that helps.

Mike
 
So the whole "find" command to move those files

Code:
find /your/data/dir -type f -mtime +7 -mtime -28 -exec mv {} /some/other/dir \;

see (and read! ;-)) the man page for find.

look for other "find" threads in this forum for more info, especially if the dest dir is a subdir of your data dir, in which case you'll need to -prune also.


HTH,

p5wizard
 
Thanks for the help guys.



--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top