[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

shell script for moving folders within a directory older than 30 days to another directory

i need a script that i can have cron run everyday, to move folders within a directory with a date of more than 30 days to another directory.

its important that the script only looks at the folder dates and not whats inside because it will start moving files out of the folders.

i want to keep the amount of orders in our order folder down to increase performance

should look something like this:

find /path/to/orderfolder -d -mtime +30 -exec mv -f {} /path/to/archivefolder \;

i get this response:
find: -d: unknown expression primary

0
dareach
Asked:
dareach
  • 2
  • 2
1 Solution
 
brettmjohnsonCommented:
If I understand your question, you only want to test the timestamp of directories.
Therefore your find command should only look for items of type directory.
I think you want to use '-type d' rather than  '-d' switch:

find /path/to/orderfolder -type d -mtime +30 -exec mv -f {} /path/to/archivefolder \;

0
 
dareachAuthor Commented:
this one didnt do anything but i didnt get an error either!

imagine opening two folders, looking at the contents side by side and sorted the first one by date. then you dragged all the folders that were older than 30 days to the other folder. that is essentialy what the script should do only without the GUI

thanks
0
 
dareachAuthor Commented:
this script seems to go inside each folder and look at the dates of the files inside and if they are older than 30 days it moves them out of the folder. thats not good, im trying to have it look only at the first level folder date and move based on that, not its contents
0
 
brettmjohnsonCommented:
I understand.   Replace '-d' with '-maxdepth 1', add '-type f' to narrow the search to ordinary files:

find /path/to/orderfolder -maxdepth 1 -type f -mtime +30 -exec mv -f {} /path/to/archivefolder \;

0
 
ozoCommented:
find /path/to/orderfolder -maxdepth 1 -type d -mtime +30 -exec mv -f {} /path/to/archivefolder \;
or
mv -f `perl -e '$,=" ";print grep -d&&-M>30,@ARGV' /path/to/orderfolder/*` /path/to/archivefolder
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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