shuf.1 (1472B)
- .\" utils-std: Collection of commonly available Unix tools
- .\" Copyright 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- .\" SPDX-License-Identifier: MPL-2.0
- .Dd October 31, 2025
- .Dt SHUF 1
- .Os
- .Sh NAME
- .Nm shuf
- .Nd print contents shuffled
- .Sh SYNOPSIS
- .Nm
- .Op Fl z
- .Op Fl n Ar num
- .Op Ar file...
- .Nm
- .Fl e
- .Op Fl z
- .Op Fl n Ar num
- .Op Ar string...
- .Sh DESCRIPTION
- In it's first form,
- .Nm
- reads lines from each
- .Ar file
- or if unspecified or when
- .Ar file
- is
- .Qq - ,
- lines are read from standard input.
- And are then shuffled and printed using a reservoir shuffle, see
- .Sx SHUFFLING
- for details.
- .Pp
- In it's second form,
- .Nm
- uses a Fisher-Yates shuffle to swap-shuffle all the strings,
- and then prints them out as lines.
- .Sh OPTIONS
- .Bl -tag -width _n_num
- .It Fl e
- Use each
- .Ar string
- as an input line.
- .It Fl n Ar num
- Output at most
- .Ar num
- lines.
- .It Fl z
- Use NULL as line delimiter, not newline.
- .El
- .Sh SHUFFLING
- In it's first form,
- .Nm
- .\" LINES_LEN
- uses a reservoir of 512 lines.
- It picks a random location,
- prints a line if present,
- then inserts a newly read line.
- Once all lines are read it prints the lines still present in the reservoir.
- .br
- While this isn't truly a random sort as lines beyond 512 won't be printed first,
- it allows to use a bounded amount of memory.
- .Sh EXIT STATUS
- .Ex -std
- .Sh SEE ALSO
- .Xr sort 1
- .Sh HISTORY
- An
- .Nm
- utility appeared in GNU coreutils 6.0.
- .Sh AUTHORS
- .An Haelwenn (lanodan) Monnier Aq Mt contact+utils@hacktivis.me