0

I want to create a random playlist for my entire music collection of 90,000 tracks. - i.e.generate a single m3u playlist containing every mp3 in every subfolder of my music folder, and present the list in random order. Any suggestions for how I can do that?

1

First, set up the list (you only need to do this when you add/delete files) :

find Music -type f -print >files.list
wc -l files.list >files.list.nlines

Then, to pick a random one,

line_number=$(echo "$(cat files.list.nlines) * $RANDOM / 32767" | bc -q)
file_to_play="$(sed -n ${line_number}p files.list)"
6
  • Thanks. The first command works well, but generates a list of all files - how would I adapt it to list just the mp3's? I can't get the 2nd command to work. When I run it I get a ">" prompt. Is there a syntax error? – user1175461 Feb 4 '19 at 23:44
  • @user1175461 Fixed. – waltinator Feb 5 '19 at 4:38
  • You can use the shuf command instead (shuf -o files.list files.list). – Olorin Feb 5 '19 at 4:40
  • Thanks - wow that shuf command worked unfeasibly quickly! – user1175461 Feb 5 '19 at 10:46
  • How can I adapt the first command to include only mp3 files? – user1175461 Feb 5 '19 at 10:50

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.