Renamed script, and made what is being deleted conditional and based on user input for piped 'grep' command

This commit is contained in:
Alex Tavarez
2025-09-12 09:47:53 -04:00
parent 2f86d2c0a5
commit c6780025f6
2 changed files with 14 additions and 4 deletions

View File

@@ -1,4 +0,0 @@
#!/bin/bash
set -euo pipefail
zfs list -t snapshot | grep 'apt-' | sed 's| .*$||g' | head -n -5 | xargs -d '\n' -I {} sudo zfs destroy {}

View File

@@ -0,0 +1,14 @@
#!/bin/bash
set -euo pipefail
zfs-clean () {
if [ -z "$1" ]; then
exit 1
elif [ "$1" == "upgrades" ]; then
if [ -z "$2" ]; then
zfs list -t snapshot | grep 'apt-' | sed 's| .*$||g' | head -n -5 | xargs -d '\n' -I {} sudo zfs destroy {}
else
zfs list -t snapshot | grep "${2}" | sed 's| .*$||g' | head -n -5 | xargs -d '\n' -I {} sudo zfs destroy {}
fi
fi
}