Skip to content

Instantly share code, notes, and snippets.

@jimdiroffii
Created April 16, 2025 17:21
Show Gist options
  • Save jimdiroffii/d6564bd339c8b7e49fd2dcfffb22b3ce to your computer and use it in GitHub Desktop.
Save jimdiroffii/d6564bd339c8b7e49fd2dcfffb22b3ce to your computer and use it in GitHub Desktop.
Rename all files in a directory to its lowercase equivalent, skip if a duplicate filename already exists
#!/usr/bin/env bash
# Just comment this out to run the script within the target directory.
cd /mnt/example || exit 1
for f in *; do
lower="$(echo "$f" | tr '[:upper:]' '[:lower:]')"
if [[ "$f" != "$lower" ]]; then
if [[ -e "$lower" ]]; then
echo "Skipping '$f': '$lower' already exists."
else
mv -- "$f" "$lower"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment