Create an m3u playlist

Using Linux BASH environment I needed to find a way to create m3u playlists.

I first trawled the Internet looking a program to automate this for me — none!

So I then decided to find the m3u file syntax to create my own by hand — none!

Reverse engineering an existing m3u (and speaking with an Apple creative genius) I found that m3u files are simply text files which point to mp3 files.

Simple I thought — just use a loop to write file names to an m3u file.

Therefore, current working directory ($CWD) /your/music, within $CWD we have many directories, listed by artist name i.e. /your/music/abba.

Furthermore, within artist directories we have albums i.e. /your/music/abba/album1; /your/music/abba/album2.

This procedure requires entering each album artist i.e. cd /your/music/abba == present working directory.

Now for the script:

for x in */*.mp3; do echo "$x" >> "${PWD##*/}.m3u"; done


We have a file with the name of the artist i.e. abba.m3u which contains a list of all mp3’s within the albums !!

Voila – Amend as necessary


I created a new script file below that allows you to pass directories into – not 100% for everyone but its a good start.

1 – Copy the code into the script

echo "m3u= $m3u"

for x in “$1″/*/*.mp3; do echo “$x” >> “/your/music/M3u/$m3u”; done

2 – add execute permissions chmod +x

3 – run sh /your/music !! do not add trailing ‘/’ !!

4 – [optional] run a for loop to recurse your main music folder for M in /your/music/*; do /bin/sh $M; done

Done I hope – let me know if you have trouble or can suggest improvements please

Enjoy !

** latest **

finished perfecting the script after many attempts and here is the final code

for i in /your/music/*; do find "$i" -maxdepth 3 -iname "*.mp3" > "$i/${i##'/your/music/'}.m3u";done


Post a comment

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.