Skip to content

Instantly share code, notes, and snippets.

@gregarious-repo
Forked from Korko/backup.sh
Created January 29, 2014 10:08
Show Gist options
  • Save gregarious-repo/8685010 to your computer and use it in GitHub Desktop.
Save gregarious-repo/8685010 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Warning, for each of these rules, we keep the oldest ones
# this is required in order to have some files in the oher category
KEEP_DAY=1 # How many to keep for each day (except for the current 24h and more than a week)
KEEP_WEEK=0 # How many to keep over a week old
for i in {1..6} ; do
# Find all files that are older than $i days and younger than ($i+1) days and remove them
find . -mtime $i -mtime -$(($i+1)) | sort | tail -n +$(($KEEP_DAY+1)) | xargs rm -Rf
done
find . -mtime +6 | sort | tail -n +$(($KEEP_WEEK+1)) | xargs rm -Rf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment