The seq
command is used to print a sequence of numbers from a starting point to an ending point in specified increments. This command is useful for generating lists of numbers or for iterating through loops in shell scripts.
Overview
The basic syntax of the seq
command is as follows:
seq [OPTION]... LAST
seq [OPTION]... FIRST LAST
seq [OPTION]... FIRST INCREMENT LAST
LAST
is the last number of the sequence.FIRST
is the first number of the sequence.INCREMENT
is the increment between each number in the sequence.
If only one argument is provided, seq
will assume that it is the LAST
argument and will generate a sequence of numbers from 1 to LAST
. If two arguments are provided, seq
will assume that the first argument is the FIRST
argument and the second argument is the LAST
argument. If three arguments are provided, seq
will assume that the first argument is the FIRST
argument, the second argument is the INCREMENT
argument, and the third argument is the LAST
argument.
Examples
- Generate a sequence of numbers from 1 to 10:
$ seq 10
1
2
3
4
5
6
7
8
9
10
- Generate a sequence of numbers from 5 to 15:
$ seq 5 15
5
6
7
8
9
10
11
12
13
14
15
- Generate a sequence of numbers from 0 to 100 in increments of 10:
$ seq 0 10 100
0
10
20
30
40
50
60
70
80
90
100
Options
The following table lists the available options for the seq
command:
Option | Description |
---|---|
-f, --format=FORMAT |
Use a specified FORMAT for the output. |
-s, --separator=STRING |
Use a specified STRING as the separator between numbers. |
-w, --equal-width |
Pad the output with leading zeros to ensure that all numbers have the same width. |
-h, --help |
Display help information and exit. |
-V, --version |
Display version information and exit. |
Troubleshooting Tips
- If you receive an error message that says “seq: invalid floating point argument”, it means that one of the arguments you provided is not an integer. Make sure that all arguments are integers.
- If you receive an error message that says “seq: zero increment”, it means that you provided an increment of 0. Make sure that the increment is greater than 0.
Notes
- The
seq
command is not available on all Linux distributions by default. If you receive an error message that says “command not found”, you may need to install thecoreutils
package.