Ubuntu – Rename *FINAL.mkv to *.mkv keeping original “*”

renamescripts

So I have a bunch of files created with the name *FINAL.mkv and I have a (1st) script to remove all the files except files with FINAL.mkv

I need help renaming the new files back to the original *.mkv, any help appreciated!

Example file tree:

Stargate.mkv

StargateFINAL.mkv

Now after 1st script

StargateFINAL.mkv

What I want to end up with (this is in regard to recursive converting of videos)

Stargate.mkv

Best Answer

Assuming the word FINAL comes only once in the filenames, you can do:

rename -n 's/FINAL//' *.mkv

This will do the dry run. After being sure you can carry out the operation :

rename 's/FINAL//' *.mkv
Related Question