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)

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">

This site uses Akismet to reduce spam. Learn how your comment data is processed.