image-file-names-to-lowercase


When building a blog with GitHub Pages, you might run into an issue where images display correctly on your local machine but fail to load online. The root cause? GitHub Pages runs on a case-sensitive file system. That means MyImage.JPG and myimage.JPG are treated as completely different files on the server.

To prevent such issues, you can batch-convert all image file names (excluding extensions) to lowercase using the following script — the extension remains unchanged:

#!/bin/bash

# Set your image directory here
IMAGE_DIR=~/Desktop/media

cd "$IMAGE_DIR" || exit 1

# Find all image files (add more extensions if needed)
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) | while read f; do
  dir=$(dirname "$f")
  filename=$(basename "$f")
  name="${filename%.*}"         # filename without extension
  ext="${filename##*.}"         # file extension

  # Generate lowercase name
  lower_name=$(echo "$name" | tr '[:upper:]' '[:lower:]')
  new_file="$dir/$lower_name.$ext"

  if [ "$f" != "$new_file" ]; then
    mv "$f" "$new_file"
  fi
done

How to Use


  1. Save the script as xxxx.sh
  2. Replace IMAGE_DIR=... with the actual path to your image folder
  3. Make the script executable and run it:
chmod +x xxxx.sh
./xxxx.sh

This helps avoid image loading failures on GitHub Pages by ensuring all file names and references match exactly — in lowercase.