-
-
Save kibotu/34a718edbed7ad1578711adf368d8974 to your computer and use it in GitHub Desktop.
Rename files and folders to lowercase recursively
This file contains 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
#!/bin/bash | |
# Rename all directories. This will need to be done first. | |
# Process each directorys contents before the directory itself | |
find * -depth -type d | while read x | |
do | |
# Translate Caps to Small letters | |
y=$(echo "$x" | tr '[A-Z ]' '[a-z_]'); | |
# create directory if it does not exit | |
if [ ! -d "$y" ]; then | |
mkdir -p "$y"; | |
fi | |
# check if the source and destination is the same | |
if [ "$x" != "$y" ]; then | |
# move directory files before deleting | |
ls -A "$x" | while read i | |
do | |
mv "$x"/"$i" "$y"; | |
done | |
rmdir "$x"; | |
fi | |
done | |
# Rename all files | |
find * -type f | while read x ; | |
do | |
# Translate Caps to Small letters | |
y=echo "$x" | tr '[a-z]' '[A-Z]' | |
if [ "$x" != "$y" ]; then | |
mv "$x" "$y"; | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment