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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

move files base on time stamps

Status
Not open for further replies.

IThead

MIS
Sep 6, 2002
102
US
hi,
How do I move a group of files base on their time stamps, for example I want to mv files that are 2 days old to other directory.

Thanks in advance!
 
The 'find' command has many options for finding files, based on many properties of files, including their age.



--
 
You can try:

Code:
To list the files
 find ./directory -atime +2 -ls 
                  -mtime +2
To remove
 find ./directory -atime +2 -exec rm {} \;

-atime = Access Time 
-mtime = Modified Time
 
how to find and move files to different directory?

I've tried this way but did not work.

find . -type f -name "log*" -mtime 1 -exec mv /home/mydir {} \;

 
KenCunningham
placing the destination dir. after {} works.

Thanks
 
I have another question, do you have a script that will mv a list for files base a range of numbers? I have some log files that is generated from Oracle like 0001_000001000.arc and the number is increamented by one, now I need some way to copy/move a certain range of these files to somewhere else.

Thanks
 
Ken is right - it's the positioning of the new directory - must be after the {} and not before
 
Depending on which number is being incremented, you can use a range in your move. Something like:

mv 000[1-9]_000001000.arc <where you're moving them to>

might do the trick or at least give you the idea. I suggest you test with ls to confirm that you're picking the correct files up before using mv.
 
KenCunningham,
I need to move a range of these files:

0001_0000025937.ARC ~ 0001_0000025940.ARC

I enter this command but did not work:

mv 0001_00000[25937-25940].ARC /tmp

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top