ls | perl -ne 'chomp; $f=$_; tr/A-Z/a-z/; s/(?<![.'"'"'])\b\w/\u$&/g; print qq{mv "$f" "$_"\n}'
perl -ne
, each input line is substituted into the $_
variable. The chomp
, tr///
, s///
perl functions in the above command all operate on the $_
variable by default.tr/A-Z/a-z/
will convert all letters to lowercase.(?<![.'])\b\w
matches any word character that follows a non-word character except a dot or a single quote. '"'"'
in the middle of the regex pattern is not a typo, but necessary for inserting a single quote into the pattern. (The first single quote closes the single quote that started the perl command, followed by a single quote enclosed within double quotes, followed by another single quote to continue the perl command.) We could have used double quotes to enclose the perl command, but then we would have to escape all the dollar signs which would make everything less readable.$&
is the letter that was matched, and by putting \u
in front it will be converted to uppercase.qq{}
in perl works like double quotes, and can make things easier to read, like in this case above when we want to include double quotes within the string to be quoted.| sh
.The above command will not work for files with double quotes in the name, and possibly other corner cases.