#!/bin/bash if (($#<3)); then echo "usage: ${0##*/} " exit 1 fi filesystem=$1 snapshotname=$2 keep=$3 keep=$((keep+1)) zfs list -H -t snapshot -o name -S creation -d1 "$filesystem" | grep "^$filesystem@$snapshotname" | tail -n +$keep | xargs -r -n 1 zfs destroy -r