Squirreling

storing bits of the internet away for a rainy day

Bash Scripting: Mp3 Renaming

Posted by squirreling on May 11, 2008

Just wrote a quick script to rename a bunch of mp3 files, removing the site name from the file.  (ie from “23 Glory [www.site.com].mp3” to “23 Glory.mp3“.  This uses the ${var%remove-from-end} bash variable manipulation.

for file in *.mp3
do
       mv "$file" "${file%\[www.site.com\].mp3}.mp3"
done

See the Advanced Variable Manipulation in Mendel Cooper’s very useful Bash Scripting Guide.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>