$linuxjunkies
>

shuf(1)

Generate random permutations of input lines or numbers.

UbuntuDebianFedoraArch

Synopsis

shuf [OPTION]... [FILE]...

Description

shuf writes a random permutation of its input lines to standard output. Each line of input becomes one line of output, but in random order. If no files are specified, shuf reads from standard input.

By default, all input lines are shuffled. Use -n to output only a subset of lines, or -e to treat command arguments as items to shuffle instead of reading from files.

Common options

FlagWhat it does
-e, --echoTreat each argument as an item to shuffle (don't read files)
-n, --head-count=NUMOutput at most NUM lines instead of all lines
-i, --input-range=LO-HITreat each number LO through HI as an input item
-z, --zero-terminatedUse NUL character instead of newline as input/output delimiter
--random-source=FILERead random bytes from FILE instead of /dev/urandom
-r, --repeatAllow output lines to be repeated (with -i or -e)

Examples

Randomly shuffle all lines from input.txt

shuf < input.txt

Randomly shuffle the four fruit names listed

shuf -e apple banana cherry orange

Output 5 random lines from /etc/passwd

shuf -n 5 /etc/passwd

Pick 10 random numbers between 1 and 100

shuf -i 1-100 -n 10

List 5 random files from the current directory

ls | shuf | head -5

Randomly pick one word from the three options

shuf -e -n 1 no yes maybe

Generate 100 random numbers 1-1000000 with repetition allowed

shuf -i 1-1000000 -n 100 -r

Related commands