I want to lowercase every directories' name under a directory. With which commands can I do that?
Lowercasing all directories under a directory
command line;directory;rename
All the directories at one level, or recursively?ZshAt one level:autoload zmvzmv -o-i -Q 'root/(*)(/)' 'root/${1:l}'Recursively:zmv -o-i -Q 'root/(**/)(*)(/)' 'root/$1${2:l}'Explanations: zmv renames files matching a pattern according to the given replacement text. -o-i passes the -i option to each mv command under the hood (see below). In the replacement text, $1, $2, etc, are the successive parenthesized groups in the pattern. ** means all (sub)*directories, recursively. The final (/) is not a parenthesized group but a glob qualifier meaning to match only directories. ${2:l} converts $2 to lowercase.PortableAt one level:for x in root/*/; do mv -i $x $(printf %s $x | tr '[:upper:]' '[:lower:]'); doneThe final / restricts the matching to directories, and mv -i makes it ask for confirmation in case of a collision. Remove the -i to overwrite in case of a collision, and use yes n | for . to not be prompted and not perform any renaming that would collide.Recursively:find root/* -depth -type d -exec sh -c '    t=${0%/*}/$(printf %s ${0##*/} | tr [:upper:] [:lower:]);    [ $t = $0 ] || mv -i $0 $t' {} \;The use of -depth ensures that deeply nested directories are processed before their ancestors. The name processing relies on there being a /; if you want to call operate in the current directory, use ./* (adapting the shell script to cope with . or * is left as an exercise for the reader).Perl renameHere I use the Perl rename script that Debian and Ubuntu ship as /usr/bin/prename (typically available as rename as well). At one level:rename 's!/([^/]*/?)$!\L/$1!' root/*/Recursively, with bash 4 or zsh:shopt -s globstar  # only in bashrename 's!/([^/]*/?)$!\L/$1!' root/**/*/Recursively, portably:find root -depth -type d -exec rename -n 's!/([^/]*/?)$!\L/$1!' {} +