🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

seq Command

Beginner Shell Scripting man(1)

Print a sequence of numbers

👁 11 views 📅 Updated: Mar 15, 2026
SYNTAX
seq [OPTION]... LAST

What Does seq Do?

seq generates a sequence of numbers. It prints numbers from a start value to an end value, optionally with a specified increment. seq is commonly used for creating numbered lists, loop counters, and test data.

seq supports integer and floating-point numbers, custom separators, and format strings for padding. It is simpler than writing for loops for numeric sequences and pairs well with xargs for parallel processing.

In bash, the brace expansion {1..10} provides similar functionality for integers, but seq offers more flexibility with custom increments, floats, and formatting.

Options & Flags

OptionDescriptionExample
LAST Print 1 to LAST seq 5
FIRST LAST Print FIRST to LAST seq 3 7
FIRST INCR LAST Print with custom increment seq 0 2 10
-s Set separator (default: newline) seq -s", " 1 5
-w Equal width (zero-padded) seq -w 1 100
-f printf-style format seq -f "file_%03g.txt" 1 5

Practical Examples

#1 Simple sequence

Prints numbers 1 through 5.
$ seq 5
Output: 1 2 3 4 5

#2 Custom range

Prints numbers 10 through 15.
$ seq 10 15
Output: 10 11 12 13 14 15

#3 Custom increment

Prints 0, 5, 10, ... 50 (increment by 5).
$ seq 0 5 50

#4 Zero-padded

Prints 001, 002, ... 100 with consistent width.
$ seq -w 1 100
Output: 001\n002\n...

#5 Custom separator

Prints comma-separated sequence.
$ seq -s", " 1 5
Output: 1, 2, 3, 4, 5

#6 Generate filenames

Generates formatted filenames.
$ seq -f "backup_%03g.tar.gz" 1 5
Output: backup_001.tar.gz backup_002.tar.gz

#7 Use in for loop

Uses seq to generate loop counter values.
$ for i in $(seq 1 5); do echo "Processing item $i"; done

Tips & Best Practices

Bash brace expansion: {1..10} generates 1 to 10 without seq. But seq supports floats: seq 0.1 0.1 1.0 and custom formatting.
Floating point: seq handles decimals: seq 0.0 0.5 5.0 generates 0.0, 0.5, 1.0, ... 5.0. Bash brace expansion cannot do this.
Large sequences: seq can generate millions of numbers. Be careful with: seq 1 1000000 | xargs command — may consume excessive memory.

Frequently Asked Questions

How do I generate a number sequence?
Use seq LAST for 1 to N, seq FIRST LAST for a range, or seq FIRST INCREMENT LAST for custom steps.
How do I zero-pad numbers?
Use seq -w for automatic padding, or seq -f '%03g' 1 100 for custom width.
What is the difference between seq and {1..N}?
seq is an external command supporting floats, formatting, and custom separators. {1..N} is bash-only but faster for simple integer ranges.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →