Batch rename filenames with this shell script

Here's a Unix shell script that converts all "*.png" files in the current directory to lower-case names. In my case I had files named "Slide1.png", etc., and I wanted them to be named "slide1.png", and this script did the trick.


# this script converts all files that match the pattern "*.png" to lower-case.

for i in `ls *.png`
  new=`echo $i | tr [A-Z] [a-z]`
  echo "Moving $orig --> $new"
  mv $orig $new

Warning: Be very careful with this script, it can do some real damage if it goes wrong. I highly recommend commenting-out the 'mv' command on your first run just to make sure it is going to work as expected. Also, I strongly recommend making a backup copy of your files.

As you can see it uses the tr command to convert all upper-case characters to lower-case characters, stores the new name in the variable named new, then uses the mv command to rename each file.