Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to be able to use kaffeine or another media player to randomly play an arbitrary number of the newest files in a particular directory. Preferably with as little typing as possible, and I am not opposed to using a script or an alias. I figure there's some way I can use head and ls -1 or some other parameter to create a list that I can pass to kaffeine (mplayer, dragon player, etc) as a parameter. I'm using bash on Ubuntu Jaunty Jackalope if it makes any difference.

share|improve this question
up vote 2 down vote accepted

Here is a function to create the file list:

function newest () {
    find . -type f -printf "%T@ %f\n" | sort -n | tail -n ${1:-15} | cut -f 2 -d " " | sort -R
}

It defaults to 15 files, but accepts a parameter for a different number. The last sort puts the list in random order.

For mplayer, you should be able to do:

mplayer $(newest 10)

or

mplayer <(newest 10)

Note that mplayer has a -shuffle option.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .