seq Command Cheat Sheet
seq prints a sequence of numbers to standard output. It is frequently used in loops and batch processing.
Synopsis
seq [OPTION]... LAST
seq [OPTION]... FIRST LAST
seq [OPTION]... FIRST INCREMENT LAST
Basic Usage
Count to 5
seq 5
# Output:
# 1
# 2
# 3
# 4
# 5
Range (Start-End)
seq 5 10
# Output: 5 6 7 8 9 10 (one per line)
Steps (Increment)
Count from 0 to 10 by steps of 2.
seq 0 2 10
# Output:
# 0
# 2
# 4
# 6
# 8
# 10
Formatting (-f)
Use printf style floating point formats.
seq -f "file_%03g.txt" 5
# Output:
# file_001.txt
# file_002.txt
# ...
Custom Separator (-s)
By default, seq uses a newline separator.
seq -s "," 1 5
# Output: 1,2,3,4,5
Practical Example
Generate a list of IPs for pinging.
for i in $(seq 100 110); do
ping -c 1 192.168.1.$i
done
Equal Width (-w)
Pad numbers with zeros to equalize width.
seq -w 9 11
# Output:
# 09
# 10
# 11
Notes
- Bash Alternative: For integer ranges, bash brace expansion
{1..5}is faster and built-in, butseqallows variables.- Bash:
echo {1..5}(Hardcoded). - Seq:
seq $start $end(Dynamic).
- Bash: