LinuxCommandLibrary

seq

Print sequences of numbers

TLDR

Sequence from 1 to 10

$ seq 10
copy

Every 3rd number from 5 to 20
$ seq 5 3 20
copy

Separate the output with a space instead of a newline
$ seq [[-s|--separator]] " " 5 3 20
copy

Format output width to a minimum of 4 digits padding with zeros as necessary
$ seq [[-f|--format]] "%04g" 5 3 20
copy

SYNOPSIS

seq [OPTION]... LAST
seq [OPTION]... FIRST LAST
seq [OPTION]... FIRST INCREMENT LAST

PARAMETERS

-f, --format=FORMAT
    Use FORMAT for printing floating-point numbers. The default is %g.

-s, --separator=STRING
    Separate numbers with STRING. The default is \n.

-w, --equal-width
    Equalize width by padding with leading zeroes.

DESCRIPTION

The seq command in Linux is a utility used to generate sequences of numbers. It prints a sequence of numbers to standard output, one number per line. It is commonly used in scripts to create loops, generate lists of files, or perform other tasks that require iterating over a series of numbers.

The basic usage of seq is straightforward, taking either a single argument (the end value) or multiple arguments (start, increment, and end values). It supports integer and floating-point numbers. The output format can be controlled using options to specify the format string. By default, the numbers are printed with a precision that matches the input. It is a simple but powerful tool for generating numerical sequences in the command line environment. If no START is given assume 1, then it is interpreted as END, otherwise START must be smaller than END. No support of increasing order from END to START

CAVEATS

The seq command is limited by the precision of the floating-point numbers used. Extremely large sequences or those with very small increments might exhibit rounding errors. seq doesn't handle decreasing sequences correctly if START is greater than END without negative INCREMENT.

EXAMPLES

seq 5: Prints numbers from 1 to 5.
seq 2 2 10: Prints numbers from 2 to 10 with an increment of 2.
seq -f "%.2f" 1 0.5 3: Prints numbers from 1 to 3 with an increment of 0.5, formatted to two decimal places.

SEE ALSO

yes(1), printf(1), jot(1)

Copied to clipboard