renamelower 461 B

1234567891011121314151617181920212223242526272829
  1. #!/bin/sh
  2. usage () {
  3. cat <<EOF>&2
  4. Usage: ${0##*/} FILES
  5. Rename FILES to lowercase if destination does not exist.
  6. EOF
  7. }
  8. [ $# -eq 0 ] && usage && exit 1
  9. [ "$1" = "-h" ] && usage && exit
  10. [ "$1" = "--" ] && shift
  11. for f ; do
  12. filename=${f##*/}
  13. case "$f" in
  14. */*) dirname="${f%/*}" ;;
  15. *) dirname="." ;;
  16. esac
  17. nf="$(echo "$filename" | awk '{print tolower($0)}')"
  18. [ "$nf" = "$filename" ] && continue
  19. newname="${dirname}/${nf}"
  20. mv -nv "$f" "$newname"
  21. done