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
| Flag | What it does |
|---|---|
-e, --echo | Treat each argument as an item to shuffle (don't read files) |
-n, --head-count=NUM | Output at most NUM lines instead of all lines |
-i, --input-range=LO-HI | Treat each number LO through HI as an input item |
-z, --zero-terminated | Use NUL character instead of newline as input/output delimiter |
--random-source=FILE | Read random bytes from FILE instead of /dev/urandom |
-r, --repeat | Allow output lines to be repeated (with -i or -e) |
Examples
Randomly shuffle all lines from input.txt
shuf < input.txtRandomly shuffle the four fruit names listed
shuf -e apple banana cherry orangeOutput 5 random lines from /etc/passwd
shuf -n 5 /etc/passwdPick 10 random numbers between 1 and 100
shuf -i 1-100 -n 10List 5 random files from the current directory
ls | shuf | head -5Randomly pick one word from the three options
shuf -e -n 1 no yes maybeGenerate 100 random numbers 1-1000000 with repetition allowed
shuf -i 1-1000000 -n 100 -r