Changing file extensions for all files in a directory on OS X

Ben McCormick picture Ben McCormick · Feb 15, 2013 · Viewed 68.8k times · Source

I have a directory full of files with one extension (.txt in this case) that I want to automatically convert to another extension (.md).

Is there an easy terminal one-liner I can use to convert all of the files in this directory to a different file extension?

Or do I need to write a script with a regular expression?

Answer

Pascal Belloncle picture Pascal Belloncle · Feb 15, 2013

You could use something like this:

for old in *.txt; do mv $old `basename $old .txt`.md; done

Make a copy first!