Harness `seq` for Effortless Numbered Loops
Quick Tip
Harness `seq` for Effortless Numbered Loops
Challenge: You need to generate a sequence of numbers for use in a loop or to create multiple files with sequential names, but doing it manually is tedious and error-prone.
The Solution: Utilize the `seq` command to generate sequences of numbers efficiently.
for i in $(seq 1 5); do echo "Processing file_$i.txt"; touch "file_$i.txt"; done
Why it works: The `seq` command generates a sequence of numbers, making it a perfect complement to shell loops or other commands that require sequential input. The syntax `seq FIRST LAST` is straightforward for basic sequences.
Pro-Tip: You can specify an increment with `seq FIRST INCREMENT LAST`, for example, `seq 0 .5 2` will output 0, 0.5, 1, 1.5, 2.
Linux Tips & Tricks | © ngelinux.com | 5/7/2026
