How to play .mp3 songs randomly by searching for them recursively in a directory and its sub directories?
linux
Solution
mpg123 -Z $(find -name "*.mp3")
The $(...) means execute the command and paste the output here.
Also, to bypass the command-line length limit laalto mentioned, try:
mpg123 -Z $(find -name "*.mp3" | sort --random-sort| head -n 100)
EDIT: Sorry, try:
find -name "*.mp3" | sort --random-sort| head -n 100|xargs -d '\n' mpg123
That should cope with the spaces correctly, presuming you don't have filenames with embedded newlines.
It will semi-randomly permute your list of MP3s, then pick the first 100 of the random list, then pass those to mpg123.
Problem
Once I am in the directory containing `.mp3` files, I can play songs randomly using ``` mpg123 -Z *.mp3 ``` But if I want to recursively search a directory and its subfolders for `.mp3` files and play them randomly, I tried following command, but it does not work. ``` mpg123 -Z <(find /media -name *.mp3) ``` `(find /media -name *.mp3)`, when executed gives all `.mp3` files present in `/media` and its sub directories. How can I get this to work?