Skip to content

Instantly share code, notes, and snippets.

@kibotu
Forked from painejake/convert_to_lower-case.sh
Created August 24, 2018 12:00
Show Gist options
  • Save kibotu/34a718edbed7ad1578711adf368d8974 to your computer and use it in GitHub Desktop.
Save kibotu/34a718edbed7ad1578711adf368d8974 to your computer and use it in GitHub Desktop.
Rename files and folders to lowercase recursively
#!/bin/bash
# Rename all directories. This will need to be done first.
# Process each directory’s 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