#!/bin/bash
if [ -z "$1" ]; then
    echo "Usage: $0 <directory or filename>"
    exit 1
elif [ -d "$1" ] ; then
    cd $1
    find . | while read fname; do
        if [ "$fname" != "." ] ; then
           newname="$(dirname "$fname")/$(basename "$fname" | tr 'A-Z' 'a-z')"
           if [[ "$fname" != "$newname" ]]; then
               mv -v "$fname" "$newname"
           fi
       fi
    done
elif [ -f "$1" ]; then
    newname="$(dirname "$1")/$(basename "$1" | tr 'A-Z' 'a-z')"
    if [[ "$1" != "$newname" ]]; then
        mv -v "$1" "$newname"
    fi
fi
#done
