{
    "mode": "info",
    "parameter": "shuf",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/shuf/json",
    "generated": "2026-11-15T15:47:11Z",
    "sections": {
        "File: coreutils.info,  Node: shuf invocation,  Next: uniq invocation,  Prev: sort invocation,  Up: Operating on sorted files": {
            "content": "",
            "subsections": [
                {
                    "name": "7.2 'shuf': Shuffling text",
                    "content": "'shuf' shuffles its input by outputting a random permutation of its\ninput lines.  Each output permutation is equally likely.  Synopses:\n\nshuf [OPTION]... [FILE]\nshuf -e [OPTION]... [ARG]...\nshuf -i LO-HI [OPTION]...\n\n'shuf' has three modes of operation that affect where it obtains its\ninput lines.  By default, it reads lines from standard input.  The\nfollowing options change the operation mode:\n\n'-e'\n'--echo'\nTreat each command-line operand as an input line.\n\n'-i LO-HI'\n'--input-range=LO-HI'\nAct as if input came from a file containing the range of unsigned\ndecimal integers LO...HI, one per line.\n\n'shuf''s other options can affect its behavior in all operation\nmodes:\n\n'-n COUNT'\n'--head-count=COUNT'\nOutput at most COUNT lines.  By default, all input lines are\noutput.\n\n'-o OUTPUT-FILE'\n'--output=OUTPUT-FILE'\nWrite output to OUTPUT-FILE instead of standard output.  'shuf'\nreads all input before opening OUTPUT-FILE, so you can safely\nshuffle a file in place by using commands like 'shuf -o F <F' and\n'cat F | shuf -o F'.\n\n'--random-source=FILE'\nUse FILE as a source of random data used to determine which\npermutation to generate.  *Note Random sources::.\n\n'-r'\n'--repeat'\nRepeat output values, that is, select with replacement.  With this\noption the output is not a permutation of the input; instead, each\noutput line is randomly chosen from all the inputs.  This option is\ntypically combined with '--head-count'; if '--head-count' is not\ngiven, 'shuf' repeats indefinitely.\n\n'-z'\n'--zero-terminated'\nDelimit items with a zero byte rather than a newline (ASCII LF).\nI.e., treat input as items separated by ASCII NUL and terminate\noutput items with ASCII NUL. This option can be useful in\nconjunction with 'perl -0' or 'find -print0' and 'xargs -0' which\ndo the same in order to reliably handle arbitrary file names (even\nthose containing blanks or other special characters).\n\nFor example:\n\nshuf <<EOF\nA man,\na plan,\na canal:\nPanama!\nEOF\n\nmight produce the output\n\nPanama!\nA man,\na canal:\na plan,\n\nSimilarly, the command:\n\nshuf -e clubs hearts diamonds spades\n\nmight output:\n\nclubs\ndiamonds\nspades\nhearts\n\nand the command 'shuf -i 1-4' might output:\n\n4\n2\n1\n3\n"
                }
            ]
        },
        "The above examples all have four input lines, so 'shuf' might produce": {
            "content": "any of the twenty-four possible permutations of the input.  In general,\nif there are N input lines, there are N!  (i.e., N factorial, or N * (N\n- 1) * ... * 1) possible output permutations.\n\nTo output 50 random numbers each in the range 0 through 9, use:\n\nshuf -r -n 50 -i 0-9\n\nTo simulate 100 coin flips, use:\n\nshuf -r -n 100 -e Head Tail\n\nAn exit status of zero indicates success, and a nonzero value\nindicates failure.\n",
            "subsections": []
        }
    },
    "flags": [],
    "examples": [],
    "see_also": []
}