Cron job to delete folder/files older than n days.
Posted on 2008-06-11
I need a simple script (cron... run daily) to do some cleanup on directories older than n days, but I need to leave the top directory intact.
So basically, I need to:
1) Get a list of all directories in my current directory (this dir will always be a year.. .2007, 2008, 2009)
2) cd to that directory and delete all directories (and files) below that are older than n days.
For instance, given the following structure:
I would need to delete mydir and yourdir if they were older than n days, while leaving the top level directory alone.
This is on solaris unix.