Pick Random Lines or Numbers with shuf
Shuffle input or draw N random picks from a file, an argument list, or a numeric range — the coreutils way to randomize anything.
01Command
$ shuf -n 3 names.txt && shuf -e --repeat -n 5 A B C D E F && seq 1 100 | shuf -n 102What it does
shuf reads lines and outputs them in random order; -n limits the output to the first N random picks instead of the whole shuffled list. -e lets you randomize items typed directly on the command line, --repeat allows the same item to appear more than once (sampling with replacement), and -i 1-100 selects from a numeric range — a dice roll or lottery without a script. It composes naturally with other tools: seq 1 100 | shuf -n 1, shuf -n 5 songs.txt | mpv --playlist=- for a random five-song queue, or shuf -n 1 users.txt to draw a raffle winner.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- shuf(1) — Linux manual pageEvidence: shuf generates random permutations: -n outputs N lines, -e treats operands as items, --repeat allows picking the same item more than once, -i picks from an integer range.
Last verified: 2026-09-18 · Category: Developer