This question already has an answer here:

I want to search and identify multiple files, within a directory, having a particular file extension (.txt) and changing the extension to (.fasta). This is considering not changing the file itself, only the extension, and saving it with the new extension.

file1.txt --> file1.fasta
file3.txt --> file2.fasta
file3.txt --> file3.fasta

marked as duplicate by Michael Mrozek Apr 13 '13 at 7:54

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.

  • The other question did NOT work for me. – bretonics Apr 17 '13 at 18:24

This is easy using a simple for loop in the shell.

for f in *.txt; do
    mv "$f" "${f%.*}.fasta"

The ${f%.*} expands to the filename without the extension.

  • Thanks! Worked perfectly! Can you explain what the (mv "$f" "${f%.*}.fasta") part is actually doing? – bretonics Apr 17 '13 at 18:24
  • @macam ${f%.*} is the filename without the extension. It simply moves the file to the filename without the extension with ".fasta" appended to the end. See BashFAQ 73. – jordanm Apr 17 '13 at 18:25

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