Change extension of many files using bash

Sometimes I need to rename a bunch (thousands) of file extensions. Doing this manual is really not feasible, so after some digging I found this solution:

for filename in *.MQ; do mv $filename `basename $filename .MQ`.XML; done

This snippet finds all files with the extension ‘MQ’ in your current folder and renames them with the extension ‘XML’.

Can be run directly on the command line in most *nix variants. Tested on Red Hat Enterprise Linux AS release 3 (Taroon Update 9)

Comments are closed.

Niklas Tech Blog
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.