Skip to content

Instantly share code, notes, and snippets.

@jpluimers
Forked from NicoDeLarge/delete_thumbsdb.sh
Created June 9, 2026 14:42
Show Gist options
  • Select an option

  • Save jpluimers/9b4364320e8f5ae3b423d6823b9e6e72 to your computer and use it in GitHub Desktop.

Select an option

Save jpluimers/9b4364320e8f5ae3b423d6823b9e6e72 to your computer and use it in GitHub Desktop.
Recursively delete Thumbs.db
#!/bin/bash
# Recursively delete all files named Thumbs.db starting from the given path (default: current directory)
# Usage: ./delete_thumbsdb.sh [--dry-run] [path]
DRY_RUN=false
TARGET_DIR="."
for arg in "$@"; do
case "$arg" in
--dry-run|-n) DRY_RUN=true ;;
*) TARGET_DIR="$arg" ;;
esac
done
if [ ! -d "$TARGET_DIR" ]; then
echo "Error: '$TARGET_DIR' is not a valid directory."
exit 1
fi
if $DRY_RUN; then
echo "[DRY RUN] No files will be deleted."
fi
echo "Searching for Thumbs.db files in: $(realpath "$TARGET_DIR")"
if $DRY_RUN; then
find "$TARGET_DIR" -type f -name "Thumbs.db" -print 2>/dev/null
else
find "$TARGET_DIR" -type f -name "Thumbs.db" -print -delete 2>/dev/null
fi
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment