Bash
Hosting
Web Development
MythTV
Cron
Email
Firefox
Exch
XUL
Linux
Windows
Wireless
Culture
VOIP
MP3
Telephony
XML
RSS
Games
Networking
DRM
Google
Microsoft
OpenOffice
PHP
Yahoo
Apple
Java
Photography
Hardware
Video
Wordpress
Javascript
Backups
Adobe
Python
Renaming MP3s in Bash
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 "\n\b")
for f in *; do
mv "$f" "$(echo $f | cut -c 4-)"
done
IFS=$SAVEIFS
This entry was posted on Tuesday, November 17th, 2009 at 11:01 am.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for f in *; do
mv "$f" "$(echo $f | cut -c 4-)"
done
IFS=$SAVEIFS