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

Repeating this command generates a new random sequence:

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