Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 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

1 Answer 1

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"
done

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.