Skip to content

Instantly share code, notes, and snippets.

@kaxing
Last active October 10, 2026 05:09
Show Gist options
  • Select an option

  • Save kaxing/1fb0c7b95419b6be03183f6554ce422a to your computer and use it in GitHub Desktop.

Select an option

Save kaxing/1fb0c7b95419b6be03183f6554ce422a to your computer and use it in GitHub Desktop.
Delete huggingface model cache(s) folder with ease.
#!/usr/bin/env bash
set -euo pipefail
d="${HF_HUB_CACHE:-${HF_HOME:-$HOME/.cache/huggingface}/hub}"
shopt -s nullglob
m=("$d"/models--*); ((${#m[@]})) || { echo "No models"; exit 0; }
for i in "${!m[@]}"; do n="${m[i]##*/models--}"; printf '%d) %s\n' "$((i+1))" "${n//--//}"; done
read -r -p "Delete #: " -a ids </dev/tty; ((${#ids[@]})) || exit 0
x=()
for i in "${ids[@]}"; do
[[ "$i" =~ ^[0-9]+$ ]] || exit 1
((10#$i >= 1 && 10#$i <= ${#m[@]})) || exit 1
x+=("${m[10#$i-1]}")
done
printf 'Delete:\n%s\n' "${x[@]}"
read -r -p "Confirm [Y/n]: " y </dev/tty
[[ "${y:-y}" =~ ^[Yy]$ ]] && rm -rfv -- "${x[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment