Back to the command reference

shuf

ShellFundamentals In simulator In real Linux

Shuffle lines randomly

Name: shuf = shuffle

You can practise it right away in the simulator, and use it in real Linux mode too.

Description

shuf randomly permutes its input lines; -n keeps N of them and -i draws from a number range. Use it for sampling, picking at random or test data.

Syntax

shuf [OPTION]... [FILE]

Common options

-n / --head-count COUNTOutput at most N lines
-i / --input-range LO-HIShuffle a number range, e.g. -i 1-100
-e / --echoShuffle the arguments given on the command line
-r / --repeatAllow repeats (with -n: draw as many as you like)
-o / --output FILEWrite the result to FILE

Examples

  • $ shuf -n 1 names.txt

    Pick a random name

    Explain
  • $ shuf -i 1-100 -n 5

    Five random numbers from 1 to 100

    Explain

Related