Files
fs-scripts/zfs/zfs-clean.sh
2025-09-17 12:34:56 -04:00

21 lines
399 B
Bash

#!/bin/bash
set -euo pipefail
REGEX='apt-'
if [ -z "$1" ]; then
exit 1
fi
if [ -n "$1" ] && [ "$1" == "upgrades" ]; then
shift
while getopts "r:" opt; do
case "$opt" in
r) REGEX=${OPTARG};;
*) exit 1;;
esac
done
zfs list -t snapshot | grep "${REGEX}" | sed 's| .*$||g' | head -n -5 | xargs -d '\n' -I {} sudo zfs destroy {}
fi