Delete all directories more than a week old
We would like to delete the directories more than 7 days from given location. we are using the below script/find command. but it is deleting the base directory as well.
HOTBACKUP_DIR=/u01/appluat/patches_OLD
export HOTBACKUP_DIR
for i in `find ${HOTBACKUP_DIR} -maxdepth 1 -type d -mtime +7 -print`; do echo -e "Deleting 7 days old directory $i"; -exec rm {} $i; done
HOTBACKUP_DIR=/u01/appluat/patches_OLD
export HOTBACKUP_DIR
for i in `find ${HOTBACKUP_DIR}/ -maxdepth 1 -type d -mtime +7 -print`; do echo -e "Deleting 7 days old directory $i"; -exec rm {} $i; done
the above script deleting the base directory "patches_OLD", becuase the base directory itself older than 7 days. We don't want to delete the base directory and would like to delet the directories older than 7 days under /u01/appluat/patches_OLD.
Please help