A script to convert all filenames to lowercase

By Alvin J. Alexander, devdaily.com

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.

#!/bin/sh

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

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

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.


devdaily logo