[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8845
  • Last Modified:

shell script to move files older that 30 days to another folder

i need a script that i can have cron run everyday to move our order files older than 30 days into another folder containing all the orders over 30 days.

i want to keep the amount of orders in our order folder down to about 3000 and we can do that by eliminating them by dates older that 30 days. anything above that and we start seeing big performance reductions.
0
dareach
Asked:
dareach
  • 7
  • 6
1 Solution
 
ozoCommented:
find /path/to/orderfolder -mtime +30 -exec mv {} /path/to/otherfolder \;
0
 
dareachAuthor Commented:
how can i make it overwrite duplicates?
0
 
ozoCommented:
Is it not doing that?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
dareachAuthor Commented:
its asking me yes or no for each file it has to overwrite
0
 
ozoCommented:
find /path/to/orderfolder -mtime +30 -exec mv -f {} /path/to/otherfolder \;
0
 
dareachAuthor Commented:
hey man, thanks for your help. i should have said this earlier. the folder im having look at is a folder with a bunch of other folders in it contaning order files, after 30 days it starts getting really big and slow so im trying to get a script that will move the folders with dates older than 30 over to another folder.
here is one line of the thousands returned by the script:

mv: rename /Volumes/Email Server_HD/OrderFiles/Temporary Items/501/Temporary Items to /Volumes/Email Server_HD/OrderFiles/*Archives/Temporary Items: Permission denied

can we have it only copy visible folders?

thanks,
brandon
0
 
ozoCommented:
What are the visible folders?   How are they distingushed from non-visible folders?
0
 
dareachAuthor Commented:
mv: rename /Volumes/Email Server_HD/OrderFiles/Temporary Items/501/Temporary Items

why is it trying to copy this, isnt that an invisible file? i dont want it to effect any hidden files in the directory its copying to. just the folders you can see which is what im trying to have copied over.
0
 
ozoCommented:
I don't have '/Volumes/Email Server_HD/OrderFiles/Temporary Items/501/Temporary Items' on my machine, so I'm not sure why it is invisible on yours
what do
ls -ld '/Volumes/Email Server_HD/OrderFiles/Temporary Items/501/'
and
ls -l '/Volumes/Email Server_HD/OrderFiles/Temporary Items/501/'
say?

Also, what is the exact command you are using?
Where does the '*Archives' come from?
In the shell, * would usually be wildcard to match any filename ending in 'Archive'
0
 
dareachAuthor Commented:
i just ran the script again and it looked in the folders and moved everything older than 30 days to the archive folder, now i have an archive folder with files instead of folders containing files. i need it to just look at the folder dates not the contents, then move the folder if its older than 30 days...
0
 
ozoCommented:
find /path/to/orderfolder -d -mtime +30 -exec mv -f {} /path/to/otherfolder \;
0
 
dareachAuthor Commented:
find /path/to/orderfolder -d -mtime +30 -exec mv -f {} /path/to/otherfolder \;

OS returns this  "find: -d: unknown expression primary"
0
 
ozoCommented:
sorry -d shoud be
-type d
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now