Skip to content

Instantly share code, notes, and snippets.

@SOSANA
Created July 18, 2023 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SOSANA/251b54396bceb24d21e7f916a00104a2 to your computer and use it in GitHub Desktop.
Save SOSANA/251b54396bceb24d21e7f916a00104a2 to your computer and use it in GitHub Desktop.
a bash script to remove all files named "file-type" in the root directory and subfolders
#!/bin/bash
# remove all files named "file-type" in the root directory and subfolders
# bash remove_files.sh
# Get the current directory
current_dir=$(pwd)
# Initialize counter for file-type files
file_type_count=0
# Find and delete files named "file-type"
while IFS= read -r -d '' file; do
rm -f "$file"
echo "Deleted: $file"
((file_type_count++))
done < <(find "$current_dir" -type f -name "file-type" -print0)
# Log the completion message with the count
echo "Deletion process completed."
echo "\"file-type\" files deleted: $file_type_count"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment