Reputation: 422
I use a 12+31 backup system -- that is, I keep one file from each month for the past year, plus one file for each day of the current month. I'm having a hard time figuring out how to build a bash script that will do the following cleanup:
For instance, if it is now November, this script would:
This will be running on a shared hosting server (Dreamhost), so I won't have the ability to install any custom CLI tools.
All of my backup files include the date in the filename, but I'd prefer to check against the file creation date if possible.
I've seen a lot of stuff on deleting files older than [x], but I'm not at all clear how to skip over files that are from the first of the month.
Upvotes: 4
Views: 2469
Reputation: 944
Here's the best I can think of for the moment:
find . -type f \ # files only
-mtime +31 \ # exclude files less than 31 days old
-printf '%Td %p\n' | # prepend filename with day of the month of last modification
grep -v '^01' |
sed 's/^[0-9][0-9] //'
Some caveats:
Upvotes: 4