I’m running into a limitation on TrueNAS where package-management tools are disabled, so I’m unable to install utilities like rename. Because of this, I’m restricted to whatever tools are already built into the system.
I need a command-line solution that can recursively rename all files and directories by converting any uppercase characters to lowercase, without making any other changes. Doing this manually would be impossible given the volume of data, so I’m hoping someone with more experience can point me in the right direction.
This is very important to me, and any help would be greatly appreciated.
Sounds easy enough to do with shellscript. You could also use python if you have more a more complex use case.
Here’s an example in shellscript. You can copy&paste that into a bash shell, then run rename_files_lowercase_recursive inside the folder where you want the renaming to occur.
For safety, the script will only print what it would do. I am leaving the removal of the safety as an exercise for the reader.
rename_files_lowercase() {
echo "Folder: $PWD"
for file in *; do
RENAMED=$(printf '%s' "$file" | tr '[:upper:]' '[:lower:]')
[ "$file" != "$RENAMED" ] && echo mv "$file" "$RENAMED"
done
}
rename_files_lowercase_recursive() {
rename_files_lowercase
for file in *; do
[ -d "$file" ] && (cd "$file" || exit 1; rename_files_lowercase_recursive)
done
}
Also note that lowercasing is locale sensitive. You’ll probably get issues if your filenames have characters which are encoded as multiple bytes.