How to Generate Number Sequences Using the seq Command in Linux

When you are architecting a bash script that requires a highly specific number of mathematical iterations (like pinging exactly 50 consecutive IP addresses or generating 100 sequential dummy files), manually hardcoding an array of numbers is catastrophically inefficient. To force the Linux kernel to algorithmically spawn a perfect, mathematical progression of integers on the fly, you must deploy the seq command.

Executing the Sequence Engine

The seq (Sequence) command is a highly optimized numerical generator. It ingests a starting boundary and an ending boundary, calculates the mathematical gap, and outputs a continuous vertical stream of ascending (or descending) integers.

Executing a Basic Loop Generation

Imagine you need to write a simple for loop in bash that executes exactly 10 times.

To execute the sequence generation, open your terminal and type:

seq 10

The exact millisecond you press Enter, the seq engine assumes a starting coordinate of 1 and generates a vertical column of integers from 1 through 10 directly to standard output.

To inject this mathematical payload directly into a bash script loop, you must utilize command substitution:

for i in $(seq 10); do
  echo "Executing iteration number: $i"
done

Modifying the Mathematical Step

If you require a highly complex numerical sequence (e.g., counting from 5 to 50, but skipping by increments of 5), you must inject all three operational boundaries: the start, the step, and the end.

seq 5 5 50

The engine will instantaneously calculate the trajectory and output: 5, 10, 15... 50. You can even force the engine to calculate in negative space to generate a descending sequence (e.g., a countdown) by injecting a negative step vector: seq 10 -1 1.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.