Renaming MP3s in Bash
Tuesday, 17 November 2009
It seems like this comes up every now and again, but I end up forgetting how to do it. So, I will post the example here, where it will live forever on the intarwebs.
While there are a ton of ways to script this, using Bash, cut, ls, find, grep, sed, awk, perl, etc… In this particular instance, I find myself with a directory of about fifty files, each named in the following manner…
- 01 Song Title.mp3
- 02 Another Song Title.mp3
- 02 Same Number Song Title.mp3
- 03 Author – Title.mp3
Bash and cut to the rescue. The following code provides for each file in the current directory to have the number stripped off of the front, even it has spaces in the filename.
#!/bin/bash SAVEIFS=$IFS IFS=$(echo -en "nb") for f in *; do mv "$f" "$(echo $f | cut -c 4-)" done IFS=$SAVEIFS