From 07b2b121c8d35998126eba1a8224a156248db87a Mon Sep 17 00:00:00 2001 From: Cryptoval2 Date: Fri, 5 Sep 2025 17:43:56 -0400 Subject: [PATCH] clean _shrunk added --- clear_shrunk.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 clear_shrunk.sh diff --git a/clear_shrunk.sh b/clear_shrunk.sh new file mode 100755 index 0000000..7d95e1b --- /dev/null +++ b/clear_shrunk.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +print_and_run() { + local cmd="$*" + printf '➜ %s\n' "$cmd" + # pipefail applies to the subshell; change/remove if not desired + bash -o pipefail -c "$cmd" +} + + +SHRUNK="/opt/vm_drive/shrunk" +LINKS="/opt/vm_drive/*.qcow2" + ACTION="echo Would remove" # default: dry-run + +DRYRUN=0 +if [[ "$1" == "--dry-run" ]]; then + DRYRUN=1 + shift +fi + +find "$SHRUNK" -maxdepth 1 -type f -printf '%f\n' \ + | grep -vxFf <(readlink -f $LINKS | xargs -n1 basename) \ + | while read -r f; do + if (( DRYRUN )); then + echo "Would remove: $SHRUNK/$f" + else + echo "Removing: $SHRUNK/$f" + rm -v -- "$SHRUNK/$f" + fi + done