Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a folder that has a number of files all of a similar form as:

Dropkick Murphys - 01 - Walk Away.mp3
Dropkick Murphys - 02 - Workers Song.mp3

And so forth...

I want to convert them all so that they appear as:

01 - Walk Away.mp3
02 - Workers Song.mp3

How can I do this?

share|improve this question
    
Are you only trying to remove Dropkick Murphys? or are you trying to rename thousands of songs to not include the artist? There are plenty of file renamers for mp3 files based on id3 tags. –  Falmarri Nov 25 '10 at 18:00
    
@Falmarri: It would be nice to know the generalized solution as well, because this scenario does occur with some frequency. –  oadams Nov 26 '10 at 6:22
add comment

6 Answers

up vote 5 down vote accepted

Under Ubuntu or Debian, it is simply:

rename 's/Dropkick Murphys - //' *mp3
share|improve this answer
    
And sometimes prename on other systems. –  ephemient Nov 25 '10 at 19:58
    
Oh, excellent; Gentoo has rename too and I've never used it. Although the syntax on Gentoo is rename from to filename... –  Michael Mrozek Nov 26 '10 at 0:10
    
@Michael: This is a different rename, please see the comment of ephemient, try prename. –  ddeimeke Nov 26 '10 at 5:58
    
There's no prename on my system. Oh well –  Michael Mrozek Nov 26 '10 at 6:47
    
I found the source code here: tips.webdesign10.com/files/rename.pl.txt found on this site tips.webdesign10.com/… –  ddeimeke Nov 26 '10 at 10:08
add comment

Pick one.

for i in *.mp3; do mv "$i" "${i#* - }"; done
for i in *.mp3; do mv "$i" "${i:19}"; done
share|improve this answer
add comment

You can use a for loop to loop over the files you want to modify. ${var/from/to} will replace the first occurrence of from with to in $var, so ${var/Dropkick Murphys - /} will replace "Dropkick Murphys - " with nothing:

for i in "Dropkick Murphys - "*; do
    mv "$i" "${i/Dropkick Murphys - /}"    
done  
share|improve this answer
add comment

Obligatory zsh answer:

autoload zmv
zmv 'Dropkick Murphys - (*.mp3)' '$1'

Variants, to do the renaming for all artist names. Note that the first command takes the longest match of the first *, e.g. it will rename Dropkick Murphys - 01 - Walk Away - concert.mp3 to Walk Away - concert.mp3.

zmv '* - (* - *.mp3)' '$1'
zmv '*.mp3' '${f#* - }'
share|improve this answer
add comment

for i in *.mp3; do mv "$i" "$(echo $i | sed 's/^Dropkick Murphys - //')"; done

or, more general, to remove first 3 space-delimited words from a file name

echo $i | cut -d' ' -f4-

share|improve this answer
    
Actually, the cut is ill-advised. A regexp scanning for - would fit better here. Tip: don't run commands you given before you understand what is going to happen and/or dry-run things using echo mv ... or smt. like that before running for reals. –  alex Nov 25 '10 at 8:46
add comment

There is a rename.ul command (I guess by default in Ubuntu). It gives you a simple way to rename files

Syntax:

$ rename from to file...
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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