in reply to random file script

On linux, it is simple to do it, sort command can randomize with -R flag:
find . -name "*mp3" | sort -R | head -n 5
An alternative can be using shuf:
find . -name "*mp3" | shuf | tail -n 5
Using perl:
find . -name "*mp3" | perl -MList::Util=shuffle -e 'print shuffle <>' + | head -n 4
Hint: You can wrap that line with a shell function

Replies are listed 'Best First'.
Re^2: random file script
by japh2963 (Novice) on Feb 05, 2015 at 03:34 UTC
    The one liners are always impressive, but the long hand version looks like a more respectable game of golf :P
      You can always add it to your profile, so not long lines are necessary :) :
      function playlist { find /home/javi/Música/ -type f | grep "$1" | shuf | head -n $2; } $ playlist mp3 10
      Long lines on shell are the unix spirit :P . Tools that only have a mission and glue magic