Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

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
share|improve this question

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

This question was marked as an exact duplicate of an existing question.

The other question did NOT work for me. – bretonics Apr 17 '13 at 18:24
up vote 0 down vote accepted

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.

share|improve this answer
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.