I have for example TREE.wav, ONE.WAV. I want to rename it to tree.wav, one.wav. How do I rename all files to lowercase?
rename "%f" "%f" - rename the file with its own name, which is actually lowercased by the dir command and /l combination.
Within Windows Explorer, right click on the file name, click on “Rename” and change the file extension to . bak and then again change it to uppercase/lowercase. In this example “. bak” extension is just an example.
Capitalize the first letter of each word in a file name. This is called “CamelCase.” It is an efficient way to differentiate words but it can be harder to read. If the file name contains a capitalized acronym, it should appear in capitals and the first letter of the following word should also be capitalized.
If you're comfortable with the terminal:
cd
and then drag and drop the Folder containing the files to be renamed into the window.ls
and hit enter.Paste this code and hit enter:
for f in *; do mv "$f" "$f.tmp"; mv "$f.tmp" "`echo $f | tr "[:upper:]" "[:lower:]"`"; done
ls
and hit enter again.(Thanks to @bavarious on twitter for a few fixes, and thanks to John Whitley below for making this safer on case-insensitive filesystems.)
The question as-asked is general, and also important, so I wish to provide a more general answer:
Simplest case (safe most of the time, and on Mac OS X, but read on):
for i in * ; do j=$(tr '[:upper:]' '[:lower:]' <<< "$i") ; mv "$i" "$j" ; done
You need to also handle spaces in filenames (any OS):
IFS=$'\n' ; for i in * ; do j=$(tr '[:upper:]' '[:lower:]' <<< "$i") ; mv "$i" "$j" ; done
You need to safely handle filenames that differ only by case in a case-sensitive filesystem and not overwrite the target (e.g. Linux):
for i in * ; do j=$(tr '[:upper:]' '[:lower:]' <<< "$i") ; [ -e "$j" ] && continue ; mv "$i" "$j" ; done
Note about Mac OS X:
Mac's filesystem is case-insensitive, case-preserving.
There is, however, no need to create temporary files, as suggested in the accepted answer and comments, because two filenames that differ only by case cannot exist in the first place, ref.
To show this:
$ mkdir test $ cd test $ touch X x $ ls -l total 0 -rw-r--r-- 1 alexharvey wheel 0 26 Sep 20:20 X $ mv X x $ ls -l total 0 -rw-r--r-- 1 alexharvey wheel 0 26 Sep 20:20 x
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With