Converting "Mixed Case" filenames to "Lower Case"
Have you ever wanted to import your photos from your camera only to find they are in "Caps" or worse Mixed case. To view any file this way it is not really a problem especially if you were to view these as called from your "filemanage" an imaging viewer is then launched as the file is selected. The Image viewer can then step through each image it sees within it list, so not a great problem then well that would be a no, "Linux" unlike Windows regards uppercase filename characters as separate characters to that of lowercase filename characters the reason for this is to extend the number of characters that make up a unique filename therefore increasing the number of files with similar names that can exist in the same directory.
So filenames like these in Windows filesystems would look Identical:
Img001.JpgIMG001.jpg
IMG001.JPG
Only one of these filenames would be allowed in Windows file systems which is a bit limiting, where as each and any variation of the above filenames would be allowed in Linux within the same directory, this can have some advantages for grouping but confusion also.
The problem comes more when your editing a file or looking for a file within a Linux filesystem, you need to adopt a standard way in which you handle all your files or just all your images. If you don't adopt a standard you can find yourself in all sorts of trouble especially when debuging your html code or finding a lost file. I maintain a standard as much as possible for all Linux files and images and that is to keep everything in a lowercase format. But how best to achieve that especially when external hardware adopts a file formating not to you liking, changing each file separately whilst achievable editing the filename of each and every filename would be very time consuming.
The majority of Web servers around the world are clearly Linux or Unix based if you create images specifically for these file systems you will already be aware of "Uppercase" and "Lowercase" in filenames. Content Management Systems use a graphical means to upload new images so is only a matter of selection and upload , bespoke web sites are a different story.
If you want to convert all your flenames for a given directory to "lowercase" then this is the command you need to use, it does not rename directories or work recursively through directories:
Run the above code and sometimes it does not work this is usually because the filename itself contains characters it does not see as alphabet text such as a space " " or an underscore the command below overcomes this limitation. To use this command and if the directory containing the files to be converted existed in "my_directory" then change directory one level before "my_directory" copy and paste the command below into the console screen and all files will be converted to lowercase letters, it will also preserve existing spaces and other characters.
This sample code iterates each time it sees a file and attempts to mv this file by reading the filename into "$f" a variable, this has echoed the result which is piped into "tr" a translator command which converts all Uppercase characters to lowercase it then looks for the next file until all filenames with Uppercase characters in the filename are processed.
Good though this command is, it does have some draw backs these are it's inability to convert directories to lower case and it's refusal to convert filenames with a space or spaces between them thus "file name.txt" all of which are legal and valid in Linux and Unix as a whole.
The safest way to use this command is to create any new directory your home directory place all the files you wish processed to lowercase into this directory open a new terminal window and change directory to the location of the folder you have just created with your images inside or files in it. Select the above command and paste this into your terminal window, press enter to run the program.
Here's a program I grabbed from the net I have'nt tried it yet but it looks as though it may work and perform at least a similar function to the single line above. I will report back with my findings.
dir="$1"
test -z "$dir" && dir=.
test -d "$dir" || exit 1
for name in $(ls "$dir"); do
newname="$(echo $name | tr '[A-Z]' '[a-z]')"
count=
if [ -f "$dir/$newname" ]; then
count=1
while [ -f "$dir/$newname$count" ]; do
count=$((count + 1))
done
fi
newname="$newname$count"
echo "$newname"
mv "$dir/$name" "$dir/$newname"
done

