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!

Script to find files before Year, and move to archive folder

Status
Not open for further replies.

saw15

Technical User
Jan 24, 2001
468
US
I am looking for a script that will find files in a specific directory ie: /myData/data/*.txt that are dated with a year prior to current year (don't want to hard code the year). Once these files are found, I want to move them into an archive directory and rename them with an extension of *.arc(/myData/archive/*.arc).

I am not a Unix guru, so looking for any kind of help. It is much appreciated.

Thanks in advance.

SAW
 
loock around, there are tousend threads playing
with date
:(
 
There's an online version of the find manual page at


There are examples of how to use the find command on that page.

You're talking about three different things here:

finding old files
moving them
renaming them

and I suggest you deal with these problems separately.

Once you're confident you're finding the correct files - add the option to the find command that moves them to the archive directory - I suggest you copy them at first rather than moving them, just in case you pick up a few files you weren't intending to.

After that's done look at renaming those files in the archive directory - though I'm not sure why you'd want to rename them as you can tell they're archive files from the name of the directory.

Mike

"Deliver me from the bane of civilised life; teddy bear envy."

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884
 
Oh - you need to look at the mtime option to find files older than a certain date - file creation time is not stored in UNIX despite rumours to the contrary.

Mike

"Deliver me from the bane of civilised life; teddy bear envy."

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

 
hi,

use this

find /dir \( -name "*.txt" -a -mtime +360 \) -exec mv /dir {} \;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top