Rename all folders and files to lowercase

A concise version using «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"
    fi
done
dev/snippets/linux/rename_all_lowercase.txt · Последние изменения: 2013/02/08 09:37 — jamis7005
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0