I’m totally in favor of people asking other people for help with these things. But here’s what Claude gave.
Found the Issue!
The problem is a mismatch between your find output and what read expects:
findwith a regular pipe outputs newline-separated filenamesread -r -d ''expects null-terminated input (the-d ''means “use null byte as delimiter”)
Solution 1: Use -print0 with find (Recommended)
Change your find command to use -print0:
find ./ -type f \( -iname "*.jpg" -o -iname "*.png" \) -print0 | while IFS= read -r -d '' file; do
Solution 2: Remove -d '' from read
find ./ -type f \( -iname "*.jpg" -o -iname "*.png" \) | while IFS= read -r file; do
Additional Issues to Fix:
- Quote your wildcards:
-iname \*.jpgshould be-iname "*.jpg"to prevent shell expansion - File extension preservation: Your script generates UUIDs but loses the file extension (
.jpg,.png). You probably want to keep those!
Improved Script:
#! /bin/bash
echo "This script will rename all files in this directory with unique names. Continue? (Y/N)"
read proceed
if [[ "$proceed" == "Y" ]]; then
echo "Proceed"
find ./ -type f \( -iname "*.jpg" -o -iname "*.png" \) -print0 | while IFS= read -r -d '' file; do
echo "in loop"
echo "$file"
# Extract the directory and extension
dir=$(dirname "$file")
ext="${file##*.}" # Get file extension
# Generate new name with UUID but keep extension
new_name="$dir/$(uuidgen -r).$ext"
echo "Renaming ${file} to ${new_name}"
# mv "$file" "$new_name" # Uncomment to actually perform the rename
done
echo "After loop"
else
echo "Cancelling"
fi
The key changes:
- Added
-print0tofind - Quoted the wildcard patterns
- Preserved file extensions using
${file##*.}
Try this and let me know if it works!




Let’s encourage human interaction rather than sending people away to an llm.