Rename files to all lowercase letters I use this Bash script to rename specified files to all lowercase letters:

#!/bin/bash

usage() {
    test $# = 0 || echo "$@"
    echo "Usage: $0 [OPTION]... FILE..."
    echo
    echo "Rename files to all lowercase letters."
    echo
    echo "  -n, --dry-run         Dry run, show what would happen"
    echo
    echo "  -h, --help            Print this help"
    echo
    exit 1
}

args=
dryrun=off
while [ $# != 0 ]; do
    case $1 in
    -h|--help) usage ;;
    -n|--dry-run) dryrun=on ;;
    --) shift; while [ $# != 0 ]; do args="$args \"$1\""; shift; done; break ;;
    -?*) usage "Unknown option: $1" ;;
    *) args="$args \"$1\"" ;;
    esac
    shift
done

eval "set -- $args"

test $# -gt 0 || usage

for path; do
    test -e "$path" || continue
    origfile=$(basename "$path")
    newfile=$(tr '[:upper:]' '[:lower:]' &lt;&lt;&lt; "$origfile")
    origdir=$(dirname "$path")
    origpath=$origdir/$origfile
    newpath=$origdir/$newfile
    test "$origpath" != "$newpath" || continue
    echo "$path -&gt; $newpath"
    test $dryrun = on || mv -i -- "$path" "$newpath"
done


Is there a better way I missed? Anything to improve?

(This script, along with many other utility scripts I use are on GitHub.)
On case-preserving but case-insensitive filesystems, renaming like that might not work, as the source and destination paths are the "same".  You may need to rename to an intermediate filename first, using mktemp.