Text and processing

The seq command

Prints a sequence of numbers, with a step, separator and format of your choice.

Syntax

seq [inicio [paso]] finTry it in the terminal →

Most useful options

-f, --format FORMATOFormats each number with a printf-style specifier, such as %g or %03g
-s, --separator CADENAText that separates the numbers. The default is a newline
-w, --equal-widthPads with leading zeros so that every number has the same width
--helpShows the help and exits
--versionShows the coreutils version and exits

Copy-ready examples

$ seq 1 5from 1 to 5, one per line.

Example output

1
2
3
4
5
$ seq 1 2 9in steps of two: start, step and end.

Example output

1
3
5
7
9
$ seq -w 8 11with leading zeros to match the width.

Example output

08
09
10
11
$ seq -s ', ' 1 4all on one line, separated by a comma and a space.

Example output

1, 2, 3, 4
$ seq -f 'foto_%03g.jpg' 1 3numbered names, useful to generate file lists.

Example output

foto_001.jpg
foto_002.jpg
foto_003.jpg

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
seq: invalid floating point argument: 'a'One of the arguments is not a number. seq accepts integers and decimals, and nothing else.Find the argument the message points to and write a number.
seq: invalid Zero increment value: '0'The step is 0, so the sequence would never advance.Use a step other than zero. To count backwards, use a negative step: seq 5 -1 1.

Typical mistakes

  • seq is not a loop: it only prints numbers. To repeat a command, use a shell loop or xargs.
  • seq 5 1 prints nothing and exits successfully. To count backwards, the step must be negative: seq 5 -1 1.
  • Decimals are matched: with seq 0 0.5 2 every number gets one decimal (0.0, 0.5, 1.0...).

Differences from similar commands

  • {1..5}: bash brace expansion: produces 1 2 3 4 5 without running any program. It works for integer ranges; seq also accepts decimals and formats.
  • printf: formats the values you pass it. seq generates the whole list, and its -f option uses the same format style.
  • xargs: takes an input and runs a command with it. seq produces the list and xargs consumes it.

Related commands

FAQ

Can I generate decimals?

Yes. seq uses for all the numbers the largest number of decimals any of the three values has: seq 0 0.5 2 gives 0.0, 0.5, 1.0, 1.5 and 2.0.

How do I count backwards?

With a negative step: seq 5 -1 1 prints 5, 4, 3, 2 and 1. With a positive step and an end smaller than the start, it prints nothing.

How do I use it inside a loop?

With command substitution: for i in $(seq 1 3); do echo "$i"; done prints 1, 2 and 3, one per line.

More Text and processing commands

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course