-
-
Save jpluimers/9b4364320e8f5ae3b423d6823b9e6e72 to your computer and use it in GitHub Desktop.
Recursively delete Thumbs.db
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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