shuf command is a Linux utility that generates a random permutation from a given input. It is a simple command-line tool that can be used to randomize the order of lines in a file or generate a random sequence of numbers.
The basic syntax of the
shuf command is as follows:
shuf [OPTION]... [FILE]
OPTION refers to the various command-line options that can be used with the command, and
FILE refers to the input file from which the random permutation is to be generated. If no input file is specified,
shuf reads from standard input.
- Generate a random permutation of numbers from 1 to 10:
shuf -i 1-10
7 1 2 9 10 3 4 5 6 8
- Generate a random permutation of lines in a file:
line 3 line 1 line 4 line 2
- Generate a random permutation of lines in a file and save it to another file:
shuf file.txt > shuffled.txt
Specific use cases
- Randomizing the order of lines in a file
- Generating a random sequence of numbers for testing or simulation purposes
- Creating randomized lists or orderings
The following table lists the available options for the
||Treat each argument as an input line|
||Treat each number in the range LO through HI as an input line|
||Output at most COUNT lines|
||Write output to FILE instead of standard output|
||Output lines can be repeated|
||Line delimiter is NUL, not newline|
- If the input file is not found, make sure the correct path is specified.
- If the output is not what you expected, check the options used and make sure they are correct.
shufcommand is available on most Linux distributions and can be installed using the package manager if not already installed.
shufcommand can be used in combination with other commands to create more complex operations.