How to change multiple file extensions


You can use this script to change a number of files with one extension (filename.old) to a different extension (filename.new) using a single command. Copy the text below into a file like mmv and put the file in your path. Then just run it.


---8<---CUT FROM HERE--- 8<---

#! /bin/csh
#
# Simple script to do a multi-mv command based on file extensions.
#
# John Yancey (jyancey@acm.org)
# Wed Mar 31 16:58:27 CST 1999

echo -n "Enter in the source file(s) extension(s) w/o the period. -> "
set EXT = $<

echo -n "Enter the destination file(s) extension(s) w/o the period. -> "
set NEXT = $<

foreach FILE ( `ls *.$EXT | awk -F"." '{print $1}'` )
        mv $FILE.$EXT $FILE.$NEXT
end

---8<---CUT TO HERE--- 8<---