-1

I have a folder with lots of files which name has the following structure:

01.artist_name - song_name.mp3

I want to go through all of them and rename them using the regexp:

/^d+\./

so i get only :

artist_name - song_name.mp3

How can i do this in bash?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
André Alçada Padez
  • 10,987
  • 24
  • 67
  • 120

3 Answers3

1

You can do this in BASH:

for f in [0-9]*.mp3; do
   mv "$f" "${f#*.}"
done 
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

Use the Perl rename utility utility. It might be installed on your version of Linux or easy to find.

rename 's/^\d+\.//' -n *.mp3

With the -n flag, it will be a dry run, printing what would be renamed, without actually renaming. If the output looks good, drop the -n flag.

janos
  • 120,954
  • 29
  • 226
  • 236
0

Use 'sed' bash command to do so:

for f in *.mp3; 
do 
    new_name="$(echo $f | sed 's/[^.]*.//')"
    mv $f $new_name
done

...in this case, regular expression [^.].* matches everything before first period of a string.

MarcM
  • 2,173
  • 22
  • 32