Code Sample |
for i in *; do [ -f "$i" ] && o=`echo "$i" | tr '[A-Z]' '[a-z]'` && mv "$i" "$o"; done |
Code Sample |
PREFIX="000_RENAME_" [ "${1}" -a -d "${1}" ] && DIR="${1}" || DIR=`pwd` cd "${DIR}" echo "You are about to rename all uppercase and mixed case files in `pwd` If this results in duplicate filenames, the second one will instead be prefixed with \"${PREFIX}\" for manual renaming later. Do you want to continue?" read anykey case ${anykey} in [Yy]|[Yy][Ee][Ss]|[Oo][Kk]) for inpoot in *[ABCDEFGHIJKLMNOPQRSTUVWXYZ]*; do # Find capitals. WHY does *[A-Z]* not work?? #echo $inpoot outpoot=`echo "${inpoot}" | tr '[A-Z]' '[a-z]'` if [ -f "${inpoot}" ]; then # rename only regular files if [ -e "${outpoot}" ]; then # don't overwrite any existing files mv "${inpoot}" "${PREFIX}${outpoot}" && echo "${outpoot} already exists...renaming to ${PREFIX}${inpoot}" else mv "${inpoot}" "${outpoot}" && echo "lowered ${inpoot}: ${outpoot}" fi fi done ;; *) exit 0;; esac |
Quote |
When you set your locale to anything other than 'C', then both [A-Z] and [a-z] become whatever the locale wants it to mean. They do not necessarily mean the same thing as [A-Za-z]. It could be, for example, that [A-Z] is an invalid regular expression, because 'Z' comes before 'A' in this locale. You are supposed to use [[:lower:]] if you want lower case letters in the current locale. |