Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 316
Ben McCormick Avatar asked Feb 15 '13 01:02

Ben McCormick


3 Answers

You could use something like this:

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

Make a copy first!

like image 172
Pascal Belloncle Avatar answered Nov 02 '22 08:11

Pascal Belloncle


Alternatively, you could install the ren (rename) utility

brew install ren

ren '*.txt' '#1.md'

If you want to rename files with prefix or suffix in file names

ren 'prefix_*.txt' 'prefix_#1.md'
like image 33
Renaud Avatar answered Nov 02 '22 07:11

Renaud


Terminal is not necessary for this... Just highlight all of the files you want to rename. Right click and select "Rename ## items" and just type ".txt" into to the "Find:" box and ".md" into the "Replace with:" box.

like image 47
Vicky Avatar answered Nov 02 '22 09:11

Vicky