Rename files to lower case on Linux or Mac

Written by
Date: 2013-01-02 21:04:32 00:00


This is a good one liner command, specially when dealing with lots of files that you want to change its names from upper-case to lower-case.

for f in * ; do mv -v $f `echo $f | tr '[A-Z]' '[a-z]'`; done

That will work on all files in the current folder, if you want more specific files use this form

for f in `find . -name '*.rar'` ; do mv -v $f `echo $f | tr '[A-Z]' '[a-z]'`; done

This last case, will look for files with .rar extension, you can use find with all its options to improve your search.

If the file_name has spaces, like "File Name.txt" use this command:

find . -depth -name '* *' | while IFS= read -r f ; do mv -v "$f" "$(dirname "$f")/$(basename "$f"|tr '[A-Z]' '[a-z]')" ; done

The command above will only work with spaces, and the first one will work only with files with no spaces, so use both if you have a mix of filenames with spaces and without them in your working folder.