shuf on Linux randomizes line order — ideal for drawing a random sample from IDs, shuffling quiz questions, or anonymizing order in exports. It is simpler than sort -R hacks and built for pipelines.
Shuffle a file
Each line stays intact; only order changes.
bashshuffle
shuf names.txt

Pick N random lines
-n outputs at most N lines without replacement.
bashsample
shuf -n 5 customers.csv

Shuf from arguments
-e shuffles a short list from the command line.
bashinline
shuf -e Mon Tue Wed Thu Fri

Reproducible tests
For deterministic QA, use a seeded language tool; shuf is for live randomness.
TipCombine
grep pattern file | shuf -n 20 for a random subset matching a filter.
Quick Reference
- Full shuffle:
shuf file - Sample:
shuf -n 5 file - List:
shuf -e a b c
Related tutorials
Diagrams are original illustrations by Gnome IT Solutions. Tutorial text © Gnome IT Solutions.