Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

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 .