#!/bin/bash # ------------------------------------------------------------ # File : ChangeExt # Author : Jonathan Franzone # Company : http://www.franzone.com # Date : 09/05/2007 # Description : Bash script to change the file extension of # a group of files. # ------------------------------------------------------------ # ------------------------------------------------------------ # Setup Environment # ------------------------------------------------------------ # ------------------------------------------------------------ # User defined functions # ------------------------------------------------------------ usage () { echo echo "Usage: `basename $0` " echo } # ------------------------------------------------------------ # Check command-line arguments # ------------------------------------------------------------ if [ -z "$3" ]; then usage exit 1 fi # ------------------------------------------------------------ # Find the files and rename them # ------------------------------------------------------------ OLDEXT=${2/#.} NEWEXT=${3/#.} find "${1}" -iname "*.${OLDEXT}" | while read F do NEWFILE="${F/%${OLDEXT}/${NEWEXT}}" echo "mv \"${F}\" \"${NEWFILE}\"" mv -f "${F}" "${NEWFILE}" done # ------------------------------------------------------------ # Done # ------------------------------------------------------------ exit 0