#!/bin/bash ## Time-stamp: <2000-06-06 18:43:03 ecl> ## Remove old backup files whose originals do not exist anymore or were ## not modified since a given amount of time. ## Intended to run as a cron job. ## Require the GNU file utilities. ## THIS FILE IS IN THE PUBLIC DOMAIN. USE AT YOUR OWN RISK! backup_files=`find . -xdev -type f \( -name '*~' -o -name '.*~' \) -print` time_stamp_file=/tmp/.clean-backups_$$ touch --time=modify --date $(date --date '3 months ago' +'%Y%m%d') $time_stamp_file for backup in $backup_files; do case $backup in *.~*~) orig=${backup%.\~*\~} ;; *~*~) orig=${backup%\~*\~} ;; *~) orig=${backup%\~} ;; *) echo Something went wrong here: \"$backup\" orig=$backup # so that the backup won't be removed. ;; esac if [ ! -f "$orig" -o "$orig" -ot "$time_stamp_file" ]; then echo rm $backup \($orig\) old_backups="$old_backups $backup" fi done rm -f $time_stamp_file $old_backups