shuf

The shuf command takes input from stdin, then passes them to stdout in random order.

The call signature is:

shuf {options} {file}

When file is specified, lines from the specified file are read and passed to stdin.

The basic operation is simple. Given the following content:

·
·
ninja$: cat colors.csv
red,#f00
green,#0f0
blue,#00f
yellow,#ff0
cyan,#0ff
magenta,#f0f
ninja$:  

The lines can be randomized using:

·
·
ninja$: shuf colors.csv
magenta,#f0f
red,#f00
cyan,#0ff
green,#0f0
yellow,#ff0
blue,#00f
ninja$:  

Repeating this command generates a new random sequence:

·
·
ninja$: shuf colors.csv
magenta,#f0f
yellow,#ff0
green,#0f0
cyan,#0ff
blue,#00f
red,#f00
ninja$:  

shuf includes the ability to generate a sequence of random integers within a specified range using the -i option, followed by a range spec. For example, to generate a sequence of random integers between 0 and 5 (inclusive):

·
·
ninja$: shuf -i 0-5
2
4
5
1
3
0
ninja$:  

shuf can also generate random sequences from a set of arguments, using the -e option. For example, to generate a random sequence of letters one could execute:

·
·
·
ninja$: shuf -e a b c d e
a
c
d
b
e
ninja$: