2

Is there anyway to shuffle songs using play on a folder using SoX?

play ~/Music/*/**

4

You can use sort -R to reorder the file list into "random" order. The command could be the following:

find ~/Music -type f | sort -R | xargs -I + play +

Here find ~/Music -type f results in a list of of all files in the Music subtree, recursively. The resulting pathname list is then "sorted" into a random order by sort -R, and passed as arguments to successive play invocations with some few/many pathnames at a time. Note the use of + as "replace string", to invoke individual play for each music file.

(Edit: as per Warren's comment below, I've now removed the useless but harmless single quotes for the second +.)

  • 1
    The '+' syntax doesn't do what you think it does. The shell will remove the quotes before passing the + to xargs. The reason it works anyway is that you're using -I which — in addition to setting a replacement string — also changes the input delimiter to newline. You could use -d '\n' to get the same effect here, since you don't need a custom command insertion point in this case. (That is, the default to tack the argument on to the end of the command is just what you want.) – Warren Young Jun 28 '16 at 16:08
  • 1
    Beware that sort -R is nonstandard. If your system doesn't have it, it may have rl or shuf instead, which do the same thing. – Warren Young Jun 28 '16 at 16:11

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.