BACKUP_DIR='/dir/to' KEEP_DAYS=7 for del in $(find $BACKUP_DIR -name '*.tar.gz' -mtime $KEEP_DAYS) do rm $del done