rename all files in folder through regular expression

280 views Asked by At

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?

3

There are 3 answers

0
janos On

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.

0
MarcM On

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.

0
anubhava On

You can do this in BASH:

for f in [0-9]*.mp3; do
   mv "$f" "${f#*.}"
done