seq — Generate number sequences
Linux / Basic Linux commands / seq.html
Prints a sequence of numbers within a range at a given step.
Basic Information
| Command Name | seq |
|---|---|
| One-line Introduction | Prints a sequence of numbers within a range at a given step. |
| Provided by | GNU coreutils |
| Official Documentation | https://man7.org/linux/man-pages/man1/seq.1.html |
| Supported Operating Systems | Linux, macOS, BSD, WSL |
| Installation Status | Installed by default |
| Category | Linux basic commands (tags: Linux basic commands (tags: seq, number, repeat, loop)) |
What is this command?
seq takes start, step and end values and prints numbers one per line. It is commonly used to build loop ranges or generate test data.
-w pads numbers to a fixed width and -f applies a printf format. Floating point is supported but precision caveats apply.
What problems does it solve?
- Building loop ranges
- Generating sequentially numbered file names
- Creating numeric test data
- Producing descending or stepped sequences
Key features
Basic sequence
Given start and end, it counts by one.
- When to use: Creating a simple range
- What you get: It plugs directly into loops.
- Limitations: Large ranges produce huge output.
Custom step
The middle argument sets the increment.
- When to use: Even numbers or steps of five
- What you get: Produces exactly the desired sequence.
- Limitations: Floating steps can accumulate rounding error.
Formatting
-w and -f control width and format.
- When to use: Zero-padding file names
- What you get: Names sort correctly.
- Limitations: A malformed format string causes an error.
Installation and usage
Check whether it is installed
seq --version
sudo apt install coreutils # Debian/Ubuntu sudo dnf install coreutils # Fedora
Real-world examples
One to five
Print a basic sequence.
seq 1 5
Custom step
Count from 0 to 10 by two.
seq 0 2 10
Zero padding
Produce 01 through 05.
seq -w 1 5