Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

seq

Print a list of numbers — for loops and test data.

Level
Everyday Linux
Group
Shell and help
Needs root
No
Package
coreutils

What it does

seq LAST prints 1 to LAST; seq FIRST LAST and seq FIRST STEP LAST set the start and step. In bash, {1..10} does the same without a program, but seq also works with variables and decimals.

How to write it

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

Options 5

Most used

-w, --equal-width
Pad with leading zeros to the same width.
-s, --separator=STRING
Separator (default a new line).
-f, --format=FORMAT
printf format for decimals, like %.2f.
--help
Show help.
--version
Show the version.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 11 to 5

    seq 5

    One number per line.

  2. 2Loop over numbers

    for i in $(seq 1 3); do echo "round $i"; done

    Also: for i in {1..3}.

  3. 3With a variable end

    N=4; for i in $(seq 1 $N); do echo $i; done

    {1..$N} does not work in bash.

  4. 4Steps

    seq 0 10 50
    0
    10
    20
    30
    40
    50

    Start, step, end.

  5. 5Count down

    seq 5 -1 1

    Negative step.

  6. 6Equal width

    seq -w 8 11
    08
    09
    10
    11

    For file names.

  7. 7One line with commas

    seq -s, 1 5
    1,2,3,4,5

    Lists for other commands.

  8. 8Ping a range of hosts

    for i in $(seq 10 20); do ping -c1 -W1 192.168.122.$i &>/dev/null && echo ".$i up"; done

    Quick scan of your own lab network.

  9. 9Create test files

    for i in $(seq -w 1 20); do touch file$i.txt; done

    file01.txt … file20.txt.

  10. 10Decimal steps

    seq -f "%.1f" 0 0.5 2

    0.0 0.5 1.0 1.5 2.0.

Exit codes

0 :: Done. 1 :: Error.

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man seq