How to turn all file names from uppercase to lowercase
En Español  

When you are downloading files from different sources, sometimes it happens that the casing is not what you would like or what you need.

Personally I like to have all the file names in lowercase, but I end up something like:

someFile.JPG aWeSoMe.pNg thisIsACamel.Svg andADocumentWeIrD.docX

This command can turn all the file names to lowercase:

for original in *; do mv $original `echo $original | tr '[:upper:]' '[:lower:]'`; done

Of course if it is just some extensions, this can be used for those common .JPG files:

for original in *.JPG; do mv $original `echo $original | tr '[:upper:]' '[:lower:]'`; done

How about those spaces in the filenames?

Many files that you get also come with spaces. I normally separate words with a ‘-’, but I am a programmer, I just like the form: ‘this-file-name.png’ But I download instead: ‘This file name.PNG’ This command can remove the spaces from the file names:

I usually replace all spaces with ‘-’

for original in *; do mv "$original" `echo $original | tr ' ' '-'`; done

Or the spaces can just be deleted:

for original in *.txt; do mv "$original" `echo $original | tr -d ' '`; done

We have pipping in Linux, we can send the result of a command and pass it to the next command, and then the next command. ‘echo’ to ‘tr’ to ‘tr’ again. This command will both turn all characters lowercase and replace spaces with '-'

for original in *; do mv "$original" `echo $original | tr '[:upper:]' '[:lower:]' | tr ' ' '-'`; done

Footnotes

There is a lot that can be done with the tr command, not just in file names but in text in general. In this particular case I utilize it to deal with file names so they adjust to my liking.