Skip to content

Instantly share code, notes, and snippets.

@geekodour
Created April 15, 2024 12:21
Show Gist options
  • Save geekodour/60dff814035ffe9d3c1bfc6c97d897e0 to your computer and use it in GitHub Desktop.
Save geekodour/60dff814035ffe9d3c1bfc6c97d897e0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Specify the directory where you want to perform the renaming
directory="."
# Move to the specified directory
cd "$directory" || exit
# Loop through all files in the directory
for file in *; do
extension="jpg"
# Check if the extension appears twice
if [[ "$file" == *."$extension"."$extension" ]]; then
# Extract the filename without the extra extension
filename="${file%.jpg.jpg}"
# Rename the file
mv "$file" "$filename.$extension"
echo "Renamed $file to $filename.$extension"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment