4

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

play ~/Music/*/**

Adam Thompson
  • 885
  • 1
  • 9
  • 18

1 Answers1

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 +.)

Ralph Rönnquist
  • 3,183
  • 1
  • 10
  • 11
  • 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`](https://arthurdejong.org/rl/) or [`shuf`](http://linux.die.net/man/1/shuf) instead, which do the same thing. – Warren Young Jun 28 '16 at 16:11