Ubuntu – Rename files with one line command

bashbatch-renamecommand line

I have this directory, and want to rename the files:

===> ls -1 Der-vierte-Weise/
10 - 10 - Erkenntniss.ogg
1 - 01 - Hoffnung.ogg
11 - 11 - Wahrheit.ogg
12 - 12 - Dankbarkeit.ogg
13 - 13 - Kredits.ogg
2 - 02 - Familie.ogg
3 - 03 - Demut.ogg
4 - 04 - Freude.ogg
5 - 05 - Schoenheit.ogg
6 - 06 - Solidaritaet.ogg
7 - 07 - Entscheidung.ogg
8 - 08 - Hilfe.ogg
9 - 09 - Unterstuetzung.ogg

The result should look like this:

===> ls -1 Der-vierte-Weise/
01 - Hoffnung.ogg
02 - Familie.ogg
...

I would like to solve this with common shell tools.

Best Answer

You could use rename...

rename -n 's/^[0-9]+ - //' *

Remove -n after testing to actually rename the files

Explanation

  • s/old/new/ replace old with new
  • ^ start of string
  • [0-9]+ some numbers