How do I rename all folders and files to lowercase on Linux? How do I rename all folders and files to lowercase on Linux? linux linux

How do I rename all folders and files to lowercase on Linux?


Smaller still I quite like:

rename 'y/A-Z/a-z/' *

On case insensitive filesystems such as OS X's HFS+, you will want to add the -f flag:

rename -f 'y/A-Z/a-z/' *


A concise version using the "rename" command:

find my_root_dir -depth -exec rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;

This avoids problems with directories being renamed before files and trying to move files into non-existing directories (e.g. "A/A" into "a/a").

Or, a more verbose version without using "rename".

for SRC in `find my_root_dir -depth`do    DST=`dirname "${SRC}"`/`basename "${SRC}" | tr '[A-Z]' '[a-z]'`    if [ "${SRC}" != "${DST}" ]    then        [ ! -e "${DST}" ] && mv -T "${SRC}" "${DST}" || echo "${SRC} was not renamed"    fidone

P.S.

The latter allows more flexibility with the move command (for example, "svn mv").


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