Take the 2-minute tour ×

How do I rename a file in linux and take the version # from the end and move it to the beginning. For example I have a file name:

Random text - text 1.1 (SD).mp3


1.1 Random text - text.mp3

Right now I can grab the version number but can't move it to the beginning, I have something like:

rename -n 's/(\d{1}\.\d{1}) \(SD\).mp3/$1.mp3/' *.mp3

which gives me

Random text - text 1.1.mp3

I tried to add a second expression group to match the beginning of the file so I can swap the beginning and the end but then nothing happens

share|improve this question
I see a space in the regex of your rename command. Is it supposed to be there, and if so should it be escaped with \? –  DarenW Sep 12 '12 at 23:16
@darenw: Spaces do not need to be escaped in regexes. –  grawity Sep 12 '12 at 23:17

2 Answers 2

The following should work:

's/^(.+?) (\d+\.\d+) \(SD\)/$2 $1/'

Or if you want to keep the (SD) part:

's/^(.+?) (\d+\.\d+) /$2 $1 /'
share|improve this answer

Your regular expression should look like this:

rename -n 's/^(.*)(\d{1}\.\d{1})(.*)$/$2 $1$3/' *.mp3
share|improve this answer

Your Answer


