I have files with the following names:


How can I rename them from the command line (using regular expression) to 1_shahlir.mp3, 2_shahlir.mp3,and so on...

closed as off-topic by terdon, Sylvain Pineau, Alaa Ali, Jacob Vlijm, αғsнιη Oct 21 '14 at 19:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – terdon, Sylvain Pineau, Alaa Ali, Jacob Vlijm, αғsнιη
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    As steeldriver said, your question is off topic here. You could ask on Super User instead. However, the solution would be something like (this assumes no spaces in your filenames, just as shown) for i in *mp3; do mv $i ${i/.mp3*/.mp3}; done – terdon Oct 21 '14 at 18:13

Try using the perl-based rename command e.g.

rename -n -v -- 's/tsb_p[.]mp3_\d+//' *.mp3

It will not actually rename your files until you remove the -n (no-operation) switch.

  • I encountered an error: sh.exe : rename : command not found. I use git bash on Win. What should I do? – Hamideh Oct 21 '14 at 18:06
  • @HamidehIraj if you are using git bash on Win, you can't expect answers on askubuntu to be relevant. I suggest you try a more appropriate StackExchange forum for your questions such as Unix & Linux – steeldriver Oct 21 '14 at 18:10

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