I have a number of files in this format:

##.## - File name.mp4

I want to rename them to:


This is what I came up with:

rename -n "s/^(\d{2})\.(\d{2}).*/s$1e$2.mp4/"

It works when I tested it on http://regexr.com/ but when I run the command on my Ubuntu 12.04 installation all my files get renamed to se.mp4

So it looks like the groups are being ignored or not inserted or something along those lines. Am I missing something blindingly obvious or is something else going on?

I ended up using pyRenamer and that worked wonderfully, but I would still like to know why rename isn't working properly.

Cheers and thanks for any help you can give me.

  • you mean s1e1.m4 , s1e2.mp4 – nux Mar 8 '14 at 2:49
  • At least one mistake: */s$1e$2.mp4/" may be * s/$1e$2.mp4/" – DK Bose Mar 8 '14 at 2:49

I think perhaps your use of double quotes is allowing the shell to expand $1 and $2

$ rename -nv "s/^(\d{2})\.(\d{2}).*/s$1e$2.mp4/" *.mp4
12.34 File name.mp4 renamed as se.mp4

whereas with single quotes around the rename expression

$ rename -nv 's/^(\d{2})\.(\d{2}).*/s$1e$2.mp4/' *.mp4
12.34 File name.mp4 renamed as s12e34.mp4
  • That was it! You sir, are a genius. – 0x0049 Mar 24 '14 at 21:18

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.