Site icon New Generation Enterprise Linux

Quick `seq` for Numbered Loops

Quick Tip

Quick `seq` for Numbered Loops

Challenge: You need to generate a sequence of numbers for a loop or to create multiple files/directories quickly in your shell script, but you don’t want to write a manual loop.

The Solution: Use the `seq` command.

seq 1 5

Why it works: The `seq` command generates a sequence of numbers, optionally incrementing by a specified step. The basic form `seq START END` prints numbers from START to END, each on a new line.

Pro-Tip: For creating numbered directories, combine `seq` with `mkdir`: mkdir dir_{$(seq -w 1 3)} will create dir_01, dir_02, and dir_03. The -w option zero-pads the numbers.

Linux Tips & Tricks | © ngelinux.com | 4/25/2026

0 0 votes
Article Rating
Exit mobile version