Skip to content

Instantly share code, notes, and snippets.

View alexwitherspoon's full-sized avatar

Alex Witherspoon alexwitherspoon

View GitHub Profile
@alexwitherspoon
alexwitherspoon / cleanup-zfs-snapshots
Created April 29, 2018 18:36 — forked from paulhandy/cleanup-zfs-snapshots
Clean up old zfs snapshots
https://serverfault.com/questions/340837/how-to-delete-all-but-last-n-zfs-snapshots#340846
You may find something like this a little simpler
zfs list -t snapshot -o name | grep ^tank@Auto | tac | tail -n +16 | xargs -n 1 zfs destroy -r
output the list of snapshot (names only) with zfs list -t snaphot -o name
filter to keep only the ones that match tank@Auto with grep ^tank@Auto
reverse the list (previously sorted from oldest to newest) with tac
limit output to the 16th oldest result and following with tail -n +16