1

I have files with the following names:

1_shahlirtsb_p.mp3_103899.mp3
2_shahlirtsb_p.mp3_103898.mp3
3_shahlirtsb_p.mp3_103897.mp3
4_shahlirtsb_p.mp3_103896.mp3
5_shahlirtsb_p.mp3_103895.mp3
6_shahlirtsb_p.mp3_103894.mp3
7_shahlirtsb_p.mp3_103893.mp3

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

1
  • 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, 2014 at 18:13

1 Answer 1

2

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.

2
  • I encountered an error: sh.exe : rename : command not found. I use git bash on Win. What should I do?
    – Hamideh
    Oct 21, 2014 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 Oct 21, 2014 at 18:10

Not the answer you're looking for? Browse other questions tagged .