Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to generate a M3U playlist for a directory containing mp3 files on my server from the terminal. Since I'd like to ensure that every player will be able to stream those files I'd like to prefix each file entry with the absolute URL to that directory, like this:

So unfortunately simply doing ls -1 *.mp3 > play.m3u isn't enough. Is there a one-liner to achieve this?

share|improve this question
up vote 3 down vote accepted

I think the following one-liner should work:

for f in *.mp3; do echo "http://..../$f" >> play.m3u; done

share|improve this answer

This is @chronitis answer with some improvements :

  • stores the file name on the variable $playlist for later use
  • will delete the file if exists previously
  • writes the full path of the file on the playlist

The command

playlist='play.m3u' ; if [ -f $playlist ]; then rm $playlist ; fi ; for f in *.mp3; do echo "$(pwd)/$f" >> "$playlist"; done

To play it with mplayer on the command line also

mplayer -playlist play.m3u
share|improve this answer
I don't know why somebody downvoted this answer. This is the only solution that seems to work right out of the box and should be accepted or at least promoted. Thank you very much! – Geppettvs D'Constanzo Feb 7 '15 at 17:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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