manpagez: man pages & more
info coreutils
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.2 shuf: Shuffling text

shuf shuffles its input by outputting a random permutation of its input lines. Each output permutation is equally likely. Synopses:

shuf [option]… [file]
shuf -e [option]… [arg]…
shuf -i lo-hi [option]…

shuf has three modes of operation that affect where it obtains its input lines. By default, it reads lines from standard input. The following options change the operation mode:


Treat each command-line operand as an input line.

-i lo-hi

Act as if input came from a file containing the range of unsigned decimal integers lohi, one per line.

shuf's other options can affect its behavior in all operation modes:

-n lines

Output at most lines lines. By default, all input lines are output.

-o output-file

Write output to output-file instead of standard output. shuf reads all input before opening output-file, so you can safely shuffle a file in place by using commands like shuf -o F <F and cat F | shuf -o F.


Use file as a source of random data used to determine which permutation to generate. See section Sources of random data.


Treat the input and output as a set of lines, each terminated by a zero byte (ASCII NUL (Null) character) instead of an ASCII LF (Line Feed). This option can be useful in conjunction with ‘perl -0’ or ‘find -print0’ and ‘xargs -0’ which do the same in order to reliably handle arbitrary file names (even those containing blanks or other special characters).

For example:

shuf <<EOF
A man,
a plan,
a canal:

might produce the output

A man,
a canal:
a plan,

Similarly, the command:

shuf -e clubs hearts diamonds spades

might output:


and the command ‘shuf -i 1-4’ might output:


These examples all have four input lines, so shuf might produce any of the twenty-four possible permutations of the input. In general, if there are N input lines, there are N! (i.e., N factorial, or N * (N - 1) * … * 1) possible output permutations.

An exit status of zero indicates success, and a nonzero value indicates failure.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© 2000-2017
Individual documents may contain additional copyright information.