Skip to content

seq Linux command

The seq command in Linux is used to generate a sequence of numbers. It can be used to create lists of numbers, either incrementing or decrementing, and allows for customization of the start, stop, and increment values. This command is useful for various tasks such as generating numeric ranges for loops, creating lists for data processing, or generating test data. By mastering the seq command, users can efficiently create sequences tailored to their specific needs.

seq Syntax:

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

Options:

OptionDescription
-w, —equal-widthEqualize width by padding with leading zeroes
-f, —format=FORMATUse printf style floating-point FORMAT
-s, —separator=STRINGUse STRING to separate numbers (default: \n)

Parameters:

ParameterDescription
FIRSTStart value
INCREMENTIncrement between each number
LASTEnd value

seq bash Examples:

Terminal window
seq 1 10

Generates a sequence of numbers from 1 to 10.

Terminal window
seq 3 2 12

Produces a sequence of numbers starting from 3 up to 12 with a step size of 2.

Display a Countdown Sequence from 10 to 1

Terminal window
seq 10 -1 1

Prints a countdown sequence from 10 to 1 in reverse order.

Create a Sequence from 0.5 to 2.5 with an Increment of 0.5

Terminal window
seq 0.5 0.5 2.5

Generates a sequence of numbers from 0.5 to 2.5 with an increment of 0.5.

Repeat a Word 5 Times Using seq and xargs

Terminal window
seq 5 | xargs -I{} echo "Word"

Repeats the word “Word” 5 times using seq in combination with xargs.

Generate a Pattern of 10 Lines with Increasing Numbers

Terminal window
seq 10 | xargs -I{} echo "Line {}"

Creates a pattern of 10 lines with numbers increasing from 1 to 10.

seq Command Help Center:

How do I use seq in Linux?

To use the seq command in Linux, execute the following command:

Terminal window
seq --option <value>

How can I generate a sequence of numbers from 1 to 10 in Linux using seq?

To generate a sequence of numbers from 1 to 10 on Linux using seq, use the following command:

Terminal window
seq 1 10

How can I generate a sequence of numbers counting by a specific increment in Linux with seq?

To generate a sequence of numbers in Linux with a specific increment, use the seq command with the increment specified. For example:

Terminal window
seq 0 2 10

How can I use seq to create a descending sequence of numbers in Linux?

To create a descending sequence of numbers using seq in Linux, specify the larger number first in the arguments. For example:

Terminal window
seq 10 -1 1

Can I format the output of seq in Linux to include leading zeros?

Yes, you can format the output of seq in Linux to include leading zeros using printf. Here is an example:

Terminal window
seq -f "%02g" 1 10

How can I use seq to create a sequence with a floating-point increment in Linux?

To create a sequence with a floating-point increment in Linux using seq, you can specify the increment as a decimal number. For example:

Terminal window
seq 1 0.5 2.5

Is it possible to use seq in Linux to generate a sequence in reverse order?

Yes, you can use seq in Linux to generate a sequence in reverse order by specifying the higher number first and the lower number second. For example:

Terminal window
seq 5 -1 1

How can I generate a sequence of characters in Linux using seq?

To generate a sequence of characters in Linux using seq, you can leverage the ASCII character set. Here is an example to generate characters from ‘a’ to ‘z’:

Terminal window
seq -f "%g" 97 122 | xargs -I{} printf "\u{} "

Applications of the seq command

  1. Generating a sequence of numbers
  2. Specifying the increment value for the sequence
  3. Generating a reversed sequence
  4. Generating a sequence with a specified format
  5. Using seq in for loops or shell scripts