rendered paste bodyNOW=`date +%s`cd $1 || exit 1mode=daycurrent_slot=0slot_filled=0for name in `ls -1d ????-??-?? | sort -n -r`; do timestamp=`date -d "${name}" +%s` age=$((${NOW}-${timestamp})) case ${mode} in day) echo "Keep ${name}" if [ ${age} -ge $((7*24*3600)) ]; then echo " Go to week mode" mode=week current_slot=`date -d "${name}" +%V` slot_filled=1 fi ;; week) weeknum=`date -d "${name}" +%V` if [ "${slot_filled}" -eq "1" -a "${weeknum}" -eq "${current_slot}" ]; then echo "Delete ${name}" mv -i "${name}" old/ else echo "Keep ${name}" if [ "${age}" -ge $((28*24*3600)) ]; then echo " Go to month mode" mode=month current_slot=`date -d "${name}" +%m` slot_filled=1 else current_slot=${weeknum} slot_filled=1 fi fi ;; month) monthnum=`date -d "${name}" +%m` if [ "${slot_filled}" -eq "1" -a "${monthnum}" -eq "${current_slot}" ]; then echo "Delete ${name}" mv -i "${name}" old/ else echo "Keep ${name}" current_slot=${monthnum} slot_filled=1 fi ;; esacdone