MPlayer:Recursively Play All Files

I’ve researched this one before and there doesn’t seem to be a real standard for how to do this (such as a -r switch for recursive play). Granted, when in Linux is there a standard for something that doesn’t really need to be standardized? In Linux land, there’s usually a minimum of several ways to do something right. Figuring out newer and more efficient ways of doing things is fun! That said, I’m going to contribute my way of doing this to the mix.

To do this, we are going to need a magical (ooo, shiny) bash one liner that involves a little process substitution (ksh, sh, and csh users, sorry. Those shells don’t support process substitution).

mplayer -playlist <(find /path/to/music -type f -name \*.ogg)

What we just did there was perform process redirection. When you run the find /mnt/music -type…, a process is started up. What the <() around the command does is create a link to the output of the pid at /dev/fd/63. A quick ls -l will show us this.

[nullspoon@null music]$ ls -l <(find /path/to/music/ -name \*.ogg)
lr-x------ 1 nullspoon nullspoon 64 Jun 14 10:00 /dev/fd/63 -> pipe:[59723]

If you want to see the contents of that file, you can simply just run the find command without anything else. If you want to see it in vim like you’re editing it, replace mplayer -playlist with vim. This will be like running vim /dev/fd/63.

vim <(find /path/to/music -type f -name \*.ogg)

Now, if you realy wanted to get crazy, you could change append to the find command a bit to listen only to music with names that have a 7 in them.

mplayer -playlist <(find /path/to/music/ -name \*.ogg | grep 7)
  1. Or sort our music backwards?

mplayer -playlist <(find /path/to/music/ -name \*.ogg | sort -r)
  1. Or a random sort?!

mplayer -playlist <(find /path/to/music/ -name \*.ogg | sort -R)

The last one is kind of pointless since mplayer has a -shuffle switch. I guess you could combine the two and get doubly shuffled music! I think Chef Elzar would have something to say about that. "BAM!!!"