Skip to content

Instantly share code, notes, and snippets.

@G33N
Last active February 22, 2023 01:07
Show Gist options
  • Save G33N/b10f3be0a997f69b77f8f12da731892e to your computer and use it in GitHub Desktop.
Save G33N/b10f3be0a997f69b77f8f12da731892e to your computer and use it in GitHub Desktop.
#!/bin/bash
# Set the directory path to rename images
directory_path="/path/to/images"
# Loop through all image files in the directory and its subdirectories
find "$directory_path" -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" \) | while read file; do
# Generate a UUIDv4 string
uuid=$(uuidgen | tr '[:upper:]' '[:lower:]')
# Get the file extension
extension="${file##*.}"
# Rename the file with the UUIDv4 string and original extension
mv "$file" "${file%/*}/${uuid}.${extension}"
done
echo "All image files in $directory_path and its subdirectories have been renamed with UUIDv4 strings."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment