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

I have about 200 files that are named like this:


and so on. I would like to rename them all to look like this:

Back Alley Uproar.avi
Bad Luck Cat.avi
Beep Beep.avi
Broomstick Bunny
Bunker Hill

and so on...

I need to use the command line as I am connected via ssh via winSCP from a windows box to get to my ubuntu server containing these files. Thanks in advance.

share|improve this question

You can use the rename command, with appropriate regular expressions e.g.


for 'replace an initial sequence of digits followed by underscore hyphen underscore'; and

s/_/ /g

to replace underscores with spaces. So

rename -nv 's/^\d+_-_//;s/_/ /g' *.avi

The -n makes it run in test (dry run) mode - test it in your directory and if you are happy that it's doing the right thing, run it without the n

share|improve this answer

You can use the following command:

rename 's/[0-9]+_-_//; s/_/\ /g' *
share|improve this answer

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.