Use of 'seq' Linux command

book

Article ID: 168140

calendar_today

Updated On:

Products

XOS

Issue/Introduction

Most Linux systems have the 'seq' command - little known but very useful.N/A

Cause

Most Linux systems have the 'seq' command on them. It's a surprisingly little known and hence underused command!

What does it do? It prints out a sequence of numbers. For example:
 
[[email protected] dev]# seq 0 5
0
1
2
3
4
5

Which doesn't look overly useful or exciting!

Yet when troubleshooting it can be put to all manner of good use. Here's one that can be immensely useful in a networking environment: exploring a network.

You aren't sure what addresses are out there... A broadcast ping is one possibility, but often falls short:
  • Broadcast domain too large to dare use it.
  • Multiple dupe results to decode.
  • And many devices simply won't respond to it.
So instead we can use a simple combination of seq and ping to explore. 

I want to test a subset of addresses on the 192.168.128.x network. I want a single ping to each - nothing too aggressive or fast.
 
for ip in `seq -w 1 10`; do ping -c 1 192.168.128.$ip; done

This will ping each address 192.168.128.1 thru 192.168.128.10 just the once, sequentially. Obviously the ping itself can be customers as required in terms fo size, timeout etc.

This is just one example of the use of 'seq'. The example itself is useful in its own right - and hopefully iuulstrates the 'seq' command and hence how it might be used in many other ways.