Created
April 16, 2025 17:21
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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