Skip to main content

Shell script to rename given file names to from uppercase to lowercase OR lowercase to uppercase.

#!/bin/sh

# to lowercase
for i in *
do
j=`echo $i | tr '[A-Z]' '[a-z]'`
mv $i $j
done

# to uppercase
for i in *
do
j=`echo $i | tr '[a-z]' '[A-Z]'`
mv $i $j
done

#################################################################################
#!/bin/bash
#
# Shell script to rename given file names to from uppercase to
# lowercase OR lowercase to uppercase
#
# http://bash.cyberciti.biz/file-management/rename-given-file-names/
# -------------------------------------------------------------------
# To rename file uppercase to lowercase create sym link:
# ln -s /path/2upper /path/2lower
#################################################################################
#
FILES="$1"
ME="$(basename $0)"

# function to display message and exit with given exit code
function die(){
  echo -e "$1"
  exit $2
}

# exit if no command line argument given
[ "$FILES" == "" ] && die "Syntax: $ME {file-name}nExamples:n $ME xyzn $ME "*.jpg"" 1 || :
# scan for all input file
for i in $FILES
do
   # see if upper to lower OR lower to upper by command name
   [ "$ME" == "2upper" ] && N="$(echo "$i" | tr [a-z] [A-Z])" ||  N="$(echo "$i" | tr [A-Z] [a-z])"
   # if source and dest file not the same then rename it
   [ "$i" != "$N" ] &&  mv "$i" "$N" || :
done