The shuf Command

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
yellow,#ff0
cyan,#0ff
red,#f00
blue,#00f
green,#0f0
magenta,#f0f
ninja$:

Repeating this command generates a new random sequence:

ninja$: shuf colors.csv
green,#0f0
blue,#00f
magenta,#f0f
yellow,#ff0
red,#f00
cyan,#0ff
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
5
4
1
3
0
2
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
e
a
b
d
c
ninja$: