Created
June 8, 2024 03:49
-
-
Save xavier-hernandez/f4979b4ce174068ce5428a26ae08be32 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# Define the directory to search (you can change this to the desired directory) | |
DIR="/temp" | |
# Array of file extensions to delete | |
EXTENSIONS=("*.txt" "*.srt" "*.nzb" "*.sup" "*.ac3" "*.dts" "*.sample.*" "*.srr") | |
# Counters for deleted files and directories | |
deleted_files=0 | |
deleted_directories=0 | |
# Loop through the array and delete the files, counting each deletion | |
for EXT in "${EXTENSIONS[@]}"; do | |
count=$(find "$DIR" -type f -name "$EXT" -print -delete | wc -l) | |
deleted_files=$((deleted_files + count)) | |
done | |
# Find and delete empty directories, counting each deletion | |
count=$(find "$DIR" -type d -empty -print -delete | wc -l) | |
deleted_directories=$((deleted_directories + count)) | |
# Output the counts | |
echo "Deleted $deleted_files files with extensions ${EXTENSIONS[*]}." | |
echo "Deleted $deleted_directories empty directories." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment