Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have about 200 files that are named like this:

01_-_Back_Alley_Uproar.avi
01_-_Bad_Luck_Cat.avi
01_-_Beep_Beep.avi
02_-_Broomstick_Bunny.avi
02_-_Bunker_Hill.avi

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

2 Answers 2

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

s/^\d+_-_//

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

 
discard

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.