play ~/Music/audio0.flac repeat -
A command for playing a single specific audio file on repeat.
play ~/Music/${random_audio_file} repeat -
A pseudo command for playing a single random audio file from the given directory (~/Music/), also on repeat.
How to do the latter as a real working command?
2 Answers
You can leverage the shuf command for that.
Try:
play "$(find ~/Music -name '*.flac' | shuf -n 1)" repeat -The double quotes are necessary in case your filenames may contain spaces.
This command will get a random .flac file and play it using omxplayer.
Modify the command to suite your player.
find . -type f -name '*.flac' | shuf -n 1 | xargs -d "\n" omxplayer