shuf flags & options

Basic usage

Randomly shuffle lines of a file.

shuf file.txt

-n

Output only N random lines.

shuf -n 5 file.txt

-i, --input-range

Generate and shuffle numbers in a range.

shuf -i 1-100
shuf -i 1-100 -n 10

-e

Shuffle command-line arguments.

shuf -e apple banana cherry grape
shuf -e -n 1 heads tails

-r, --repeat

Allow repeats (sampling with replacement). Use with -n.

shuf -r -n 5 -e red green blue

-o, --output

Write output to a file.

shuf -o shuffled.txt file.txt

Random line from a file

Pick one random line.

shuf -n 1 quotes.txt

Random number

Generate a random number in a range.

shuf -i 1-1000 -n 1