#!/bin/sh [ -z "$1" ] && { printf "Provide number of snapshots to keep\n" exit 1 } [ $1 -gt 0 ] || { printf "%s doesn't look like a positive number\n" "$1" exit 1 } restic snapshots -c printf "Will delete these snapshots:\n" "$1" restic snapshots -c | awk 'NR>2 && !/^-+$/ && !/^[0-9]* snapshots$/ {print $1}'|head -n -"$1" printf "Proceed? [y/N]\n" "$1" read answer [ "$answer" = "y" ] && { restic snapshots -c | awk 'NR>2 && !/^-+$/ && !/^[0-9]* snapshots$/ {print $1}'|head -n -"$1"|xargs -n 1 restic forget restic prune }