I have an Ubuntu server installation set up as a media server with Subsonic in a medium sized office environment. I allow uploads from all employees to the media folder on the server.

As you can imagine, it's going to get a bit messy in there with multiple spellings of artist and album names for directory names, duplicate files, and incorrect filenames and tags.

I was hoping I could find a script that I could run daily as a cron job to clean up the media drive. Does anyone know of any that might work? I would like to maintain a path similar to: /mnt/music/Artist/Album/Song.file

2 Answers 2


I found this script http://www.skryking.net/post/bash-sort-mp3-s-by-id3-tag:

IFS=$(echo -en "\n\b")

for i in `ls -1 *.mp3`
TITLE="`id3info "$i" | grep '^=== TIT2' | sed -e 's/.*: //g'`"
ARTIST="`id3info "$i" | grep '^=== TPE1' | sed -e 's/.*: //g'`"
ALBUM="`id3info "$i" | grep '^=== TALB' | sed -e 's/.*: //g'`"
YEAR="`id3info "$i" | grep '^=== TYER' | sed -e 's/.*: //g'`"
TRACKNUM="`id3info "$i" | grep '=== TRCK' | sed -e 's/.*: //g'`"

if [ -e "$TITLE" ]; then

if [ -e "$ARTIST" ]; then

if [ -e $ALBUM ]; then

if [ -e $YEAR ]; then

if [ -e $TRACKNUM ]; then


install -D "$i" /storage/Multimedia/Music/"$ARTIST"/"$ALBUM"/"$i"
echo "/storage/Multimedia/Music/$ARTIST/$ALBUM/$i" >> filelist.txt



Obviously you will need to modify this to use your specific folders. It requires all the unsorted music to be in one folder and doesn't go into sub folders but other than that it's great.


I used to have a similar arrangement. The method I settled for was not letting people write to the actual end directory and instead had an incoming directory that once a day processed all the files and in doing so, moved them to the music directory.

I found this a lot better as I could deal with metadata and get rid of junk files all in one swoop.

This isn't going to be the most useful post because I lost the script I wrote to do this. It was a Python script that grabbed album art from Amazon, checked CDDB if there wasn't metadata, etc. If you're looking for a quick Python project, I can heartily recommend it - It was fun.

Otherwise, you could use the incoming arrangement and run something like Banshee which has a great music-organising engine within it. The only problem is you'd have to do the imports manually as I don't think there's an auto-import function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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