jmhobbs

Renaming Your 'The' Folders

I was working on tagging and ordering my music collection tonight and had to decide what to do with all my artisit folders that are named leading with "The", e.g. "The Weakerthans" or "The Strokes". I decided to go with moving the "The" to the end so that "The Weakerthans" becomes "Weakerthans, The" and is placed with the W's in an alphabetical sort.

To do this I used a nice one-liner that leverages the rename tool. It's just a regular expression but it does it nicely.

rename 's/^(The) (.*)/$2, $1/' *

I recommend running it with the -n flag first to make sure it's going to do exactly what you think it is. I also came up with a line to do the reverse, just in case you decide you don't like it that way.

rename -n 's/(.*), (The)$/$2 $1/' *

Regular expressions rock.

Update (01/08/07)
Bonus! If you have all your music (or something else) organized by folders I recommend using the tree tool to get a nice text representation of your collection. I don't know about other distro's but it's not installed in the default Ubuntu Edgy 6.10, so you'll want to grab it with:

sudo apt-get install tree

After that it's a snap, just run it on your directory and divert the output into a file. Here's my run on my music collection, and you can view the produced file here (11k)

tree -d /media/hdb/Music/  > musicList.txt