Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Possible Duplicate:
Rename a group of files with one command

I have a directory having .txt files. I need to rename the extension of all the files to .xml. How can I do this in command line?

I am using Mac OS X 10.7.3


share|improve this question

marked as duplicate by grawity, Ƭᴇcʜιᴇ007, random Apr 8 '12 at 3:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

up vote 4 down vote accepted

Open a terminal window and use this command:

for i in *.txt; do
    mv "$i" "${i%.*}.xml"
share|improve this answer
Breaks on files with spaces in their name. Also, for ... ls *.txt is extremely redundant. Could have been for i in *.txt, but that's not a safe way to iterate over files either. –  slhck Apr 7 '12 at 22:16
@slhck: In what way is it unsafe? –  grawity Apr 7 '12 at 22:35
@Scott: Please do not use for i in `ls`. See BashPitfalls #1 and #2. –  grawity Apr 7 '12 at 22:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.