General
cancel
Showing results for 
Search instead for 
Did you mean: 

How to move files over a certain age to a different directory

SOLVED
Go to solution
Andrew Kaplan
Super Advisor

How to move files over a certain age to a different directory

Hi there --

I need to move a large series of files that are over a certain age, ie: dated or time stamped before January 1 2009, from one directory to another one.

What would the correct syntax be in order to accomplish this? The operating system in question is HP-UX 11.00. Thanks.
A Journey In The Quest Of Knowledge
6 REPLIES
Pete Randall
Outstanding Contributor
Solution

Re: How to move files over a certain age to a different directory

something like this:

touch reference -t[[CC]YY]MMDDhhmm[.SS]

find onedir -type f ! -newer reference |xargs mv anotherdir

Without testing, I think that's right.


Pete

Pete
Tim Nelson
Honored Contributor

Re: How to move files over a certain age to a different directory

cd /path/to/files
find ./ -type f -mtime +365 -exec mv {} /new/dir/ \;

some form of this should do it..
Pete Randall
Outstanding Contributor

Re: How to move files over a certain age to a different directory

Here, this one does work:

touch reference -t[[CC]YY]MMDDhhmm[.SS]

find onedir -type f ! -newer reference -exec mv {} /anotherdir \;


Pete

Pete
Andrew Kaplan
Super Advisor

Re: How to move files over a certain age to a different directory

Hi there --

Thanks for your responses. I implemented Tim Nelson's suggestion, and it worked very well.

I will make sure to assign points to both of you, and even though I did not use Pete Randall's method, the least I can do is to give points as gratitude.

Thanks again to you both.
A Journey In The Quest Of Knowledge
Viktor Balogh
Honored Contributor

Re: How to move files over a certain age to a different directory

Hi,

just a note: mv can handle multiple parameters too, so this solution would be faster than the above

find ./ -type f -mtime +365 -exec mv {} /new/dir/ \+

note the + sign at the end instead of ; -> this feeds all the founded files to a single mv process
****
Unix operates with beer.
Dennis Handly
Acclaimed Contributor

Re: How to move files over a certain age to a different directory

>Viktor: mv can handle multiple parameters too, so this solution would be faster than the above

Except you can't get there from here.

>find ./ -type f -mtime +365 -exec mv {} /new/dir/ +

The Posix standard only allows you to put the {} right before the +.
See these other threads where I introduce an auxiliary script to do the work:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1331996
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1133772
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1383497
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1111050