Created
June 22, 2019 17:51
-
-
Save zorael/6ca79718cc95f8237d1b0e705f81715b to your computer and use it in GitHub Desktop.
Recursively changes the names of all files and directories to lowercase (no support for symlinks)
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/sh | |
rename_twice() { | |
local IFS | |
local from="$1" | |
local to="$2" | |
[ "$from" = "$to" ] && return | |
mv "$from" "${from}_" | |
mv "${from}_" "$to" | |
} | |
rename_dirs() { | |
local IFS lower dir | |
find -maxdepth 1 -type d | while read dir; do | |
[ "$dir" = "." ] && continue | |
lower="$(echo "$dir" | tr '[A-Z]' '[a-z]')" | |
rename_twice "$dir" "$lower" | |
cd "$lower" 2>/dev/null || continue | |
printf 'd' | |
rename_dirs | |
cd .. | |
done | |
} | |
rename_files() { | |
local IFS lower file | |
find ! -type d | while read file; do | |
lower="$(echo "$file" | tr '[A-Z]' '[a-z]')" | |
rename_twice "$file" "$lower" | |
printf 'f' | |
done | |
} | |
rename_dirs | |
echo | |
rename_files | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment