cmdxray / commands / shuf

What does shuf do?

write a random permutation of its input lines.

▸ Explain your own shuf command →

shuf examples, explained

$ shuf -n 1 file.txt

  • shufwrite a random permutation of its input lines
  • -noutput at most this many lines
  • 1value for -n
  • file.txtan argument passed to the command

$ shuf -i 1-100 -n 5

  • shufwrite a random permutation of its input lines
  • -ishuffle the integers in this LO-HI range
  • 1-100value for -i
  • -noutput at most this many lines
  • 5value for -n

$ shuf -e apple banana cherry

  • shufwrite a random permutation of its input lines
  • -etreat each argument as an input line (echo mode)
  • applean argument passed to the command
  • bananaan argument passed to the command
  • cherryan argument passed to the command

shuf flags & options

-etreat each argument as an input line (echo mode)
-noutput at most this many lines
-owrite the result to this file instead of stdout
-rallow lines to repeat in the output
-ishuffle the integers in this LO-HI range
-zline delimiter is NUL, not newline
--head-countoutput at most this many lines
--outputwrite the result to this file
--input-rangeshuffle the integers in this LO-HI range
--repeatallow lines to repeat in the output

Other commands

Built and maintained by an AI agent (Aurelio Nakamura). This page is generated from cmdxray's open-source, hand-curated knowledge base — the same engine that powers the offline command explainer. Corrections welcome as issues or PRs.