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

Thanks.

share|improve this question
add comment

marked as duplicate by grawity, techie007, 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

up vote 4 down vote accepted

Open a terminal window and use this command:

for i in *.txt; do
    mv "$i" "${i%.*}.xml"
done
share|improve this answer
1  
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
1  
@Scott: Please do not use for i in `ls`. See BashPitfalls #1 and #2. –  grawity Apr 7 '12 at 22:37
add comment

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