I have a list of thousand files which have filenames with .txt.txt appended twice, I want to remove the second .txt from the file. for eg.

File1.txt.txt is the original file.

I want to rename it to File1.txt

I cannot do it manually because there are thousand files. I tried different combinations using mv command but got no luck. Please help.


Run the below rename command on the directory where *.txt.txt files are stored,

rename 's/\.txt$//' *.txt

It checks for the files ended with .txt if it find any then it removes the last .txt part.


If the folder conatins files in both formats like file.txt.txt and file.txt, you could run the below command to remove the last .txt part from only the files which has the format file.txt.txt,

rename 's/\.txt$//' *.txt.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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