shuf
Text processing
Usage
shuf [file]Prints its input lines in random order; it is GNU coreutils and absent on macOS, where the usual stand-in sort -R groups equal lines together.
Common flags
| Flag | Meaning |
|---|---|
| -n | Print only N lines |
| -e | Treat the arguments themselves as the lines |
| -i | Draw from a number range, as in -i 1-100 |
| -r | Allow the same line to come out more than once |
| -o | Write to a file instead of standard output |
| --random-source | Use a fixed source so the shuffle can be repeated |
Examples
shuf -n 1 names.txtPicks one line at random.
shuf -i 1-49 -n 6Six different numbers between 1 and 49.
sort -R names.txtThe nearest thing on a machine without shuf.
These were built to be piped together. Three joined commands are usually shorter than one that does everything.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does shuf do?
Prints its input lines in random order; it is GNU coreutils and absent on macOS, where the usual stand-in sort -R groups equal lines together.
Q. How do I type it?
shuf [file] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man shuf. This command sits under Text processing.
Related commands
man page: man shuf