Changing File Extensions
April 20th, 2007 by Andrew
Today at work I needed to change a whole directory (with many sub-directories and sub-sub-directories and… etc.) of .php files to the .html file extension. Since the files were on a Unix server, I wrote a quick Bash shell script to take care of this for me.
#!/bin/bash function change_extension_recursive { #change all .php to .html for f in $1/*.php; do mv $f $1/`basename $f .php`.html; echo $f; done; # recurse on any directories for d in $1/*; do if test -d $d; then change_extension_recursive $d; fi; done; } dir=`pwd`; change_extension_recursive $dir;
flickr.com/photos/andrewmwhalen
linkedin.com/in/andrewmwhalen
twitter.com/awhalen
youtube.com/user/whalena