Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

this one should be simple for anyone who knows the correct way to escape. I'm attempting to batch rename a few hundred files that had \u0026amp; pushed into the file names instead of and or &. I tried using:

rename s/"\\u0026amp;"/"and"/g * but and getting names like Excision \uand Datsik - Calypso.mp3 you can see the \u wasn't escaped properly. What's the way to escape my \??


share|improve this question
up vote 3 down vote accepted

Not sure why you're using quotes like that. Here's how I use rename:

rename 's/search/replace/' *

And here's it in action:

oli@bert:~/Desktop/rawr$ ls
oli@bert:~/Desktop/rawr$ rename 's/\\u333/PIE/' *
oli@bert:~/Desktop/rawr$ ls

Your quotes seem to be throwing it off.

share|improve this answer
You're right, it was requiring it to need ANOTHER trailing slash, see above (or below, depending on post angle). Up for noticing it too. – ehime Apr 16 '12 at 23:20
Backslash is interpreted by the shell within double quotes (not single), so Perl sees s/\u0026amp;/and/g. \u means "uppercase next char", which pointlessly capitalizes 0. So, it's equivalent to s/0026amp;/and/g: only the 0026amp; is replaced and the \u is left behind. Short story is you should always use singlequotes with rename. – poolie Apr 16 '12 at 23:28

I needed more trailing slashes evidently... =(

rename s/"\\\u0026amp;"/"and"/g *

share|improve this answer
If you're going to double-escape the backslashes, you should really have four: otherwise you're just relying on the shell expanding \u to \u and that won't work in other cases. – poolie Apr 16 '12 at 23:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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