Remove all ZFS snapshots

Here’s a small bash script to destroy all existing zfs snapshots.

Run at your own risk!  :-)

#!/bin/bash
for snapshot in `zfs list -H -t snapshot | cut -f 1`
do
zfs destroy $snapshot
done



Related posts:
  1. 10 steps to a Xen domU
  2. ZFS: The future of filesystems?

4 Comments

  1. slawko:

    Hi,
    It’s better to get rid of cut command:
    for snapshot in `zfs list -H -o name -t snapshot`
    (…)

    :)

  2. Anders:

    Well,

    zfs list -H -o name -t snapshot | xargs -n1 zfs destroy

    is even better :-)

  3. Luke Sheldrick:

    Nice. Ta

  4. hseldon:

    I found that when deleting snapshots from multiple shares this works okay:

    zfs list -H -o name -t snapshot|grep nameofzfsshare|pfexec xargs -n1 zfs destroy

Leave a comment