Skip to content

Instantly share code, notes, and snippets.

@xavier-hernandez
Created June 8, 2024 03:49
Show Gist options
  • Save xavier-hernandez/f4979b4ce174068ce5428a26ae08be32 to your computer and use it in GitHub Desktop.
Save xavier-hernandez/f4979b4ce174068ce5428a26ae08be32 to your computer and use it in GitHub Desktop.
#!/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