This article will explain how to change the file extension for all files in a directory in Linux using a simple bash shell command. While you are on a learning path, be sure to checkout other useful Linux articles such as Insert/Add String to Beginning of a File and Linux – How to find the number of files in a folder.
Change from one extension to another in Linux
The command below will rename all files with the extension .php4 to .phpfor f in *.php4; do mv $f `basename $f .php4`.php; done;
Add (append) an extension to all files
The command below add the extension .txt to all files in the directoryfor f in *; do mv $f `basename $f `.txt; done;
Remove (delete) an extension from all files
The command below remove the extension .txt from all files in the directoryfor f in *.txt; do mv $f `basename $f .txt`; done;