Linux – How to remove trailing characters in filenames in Bash

bashlinuxrename

I have a bunch of media files like those below:

tvshow.s01e11]Bloodlines.avi
tvshow.s01e12]suffer.avi
tvshow.s01e13]NotMe.avi

I would like to rename them to

tvshow.s01e11.avi
tvshow.s01e12.avi
tvshow.s01e13.avi

I’ve tried using rename but evidently I’m not getting the syntax right because it fails.

Best Answer

This will rename the files. You need the \w* to signify any number of alphanumeric characters.

rename 's/\]\w*//' *

Reference: http://www.troubleshooters.com/codecorn/littperl/perlreg.htm#UsingSimpleWildcards

Related Question