Skip to content

Instantly share code, notes, and snippets.

@SOSANA
Last active July 18, 2023 17:07
Show Gist options
  • Save SOSANA/2090d3e66a1498be5b6f40f9cb2d713c to your computer and use it in GitHub Desktop.
Save SOSANA/2090d3e66a1498be5b6f40f9cb2d713c to your computer and use it in GitHub Desktop.
a bash script to remove all files containing .json and -edited.jpg from root folder
#!/bin/bash
# remove all files containing .json and -edited.jpg. Place in root subfolder and will remove from all subfolders
# bash remove_files.sh
# Get the current directory
current_dir=$(pwd)
# Initialize counters for json and edited jpg files
json_count=0
edited_jpg_count=0
# Find and delete all files with a .json extension
while IFS= read -r -d '' file; do
rm -f "$file"
echo "Deleted: $file"
((json_count++))
done < <(find "$current_dir" -type f -name "*.json" -print0)
# Find and delete all files that have "-edited" in the name with a .jpg extension
while IFS= read -r -d '' file; do
rm -f "$file"
echo "Deleted: $file"
((edited_jpg_count++))
done < <(find "$current_dir" -type f -name "*-edited.jpg" -print0)
# Log the completion message with the counts
echo "Deletion process completed."
echo "JSON files deleted: $json_count"
echo "Edited JPG files deleted: $edited_jpg_count"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment