dareach
asked on
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
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
ASKER
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
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
ASKER
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
or
mv -f `perl -e '$,=" ";print grep -d&&-M>30,@ARGV' /path/to/orderfolder/*` /path/to/archivefolder
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 \;