Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Simple question: how to make ping on Linux to show line numbers in output?

I mean:

1 64 bytes from www.site.com ( icmp_req=1 ttl=247 time=17.9 ms
2 64 bytes from www.site.com ( icmp_req=2 ttl=247 time=16.1 ms
3 64 bytes from www.site.com ( icmp_req=3 ttl=247 time=16.1 ms
share|improve this question
add comment

1 Answer

The nl command adds line numbers to its input, so you can pipe the output of ping to nl.

% ping -c3 google.com | nl
     1  PING google.com ( 56(84) bytes of data.
     2  64 bytes from nuq04s08-in-f9.1e100.net ( icmp_req=1 ttl=55 time=31.2 ms
     3  64 bytes from nuq04s08-in-f9.1e100.net ( icmp_req=2 ttl=55 time=14.8 ms
     4  64 bytes from nuq04s08-in-f9.1e100.net ( icmp_req=3 ttl=55 time=16.3 ms

     5  --- google.com ping statistics ---
     6  3 packets transmitted, 3 received, 0% packet loss, time 2002ms
     7  rtt min/avg/max/mdev = 14.851/20.833/31.286/7.417 ms
share|improve this answer
Wow, cool. Didn't know of nl previously. –  EEAA Jul 17 '12 at 6:33
@ErikA Yup, it's even part of POSIX. –  mgorven Jul 17 '12 at 6:35
... and after all these years I learn about nl. Apparently it also has other meanings than Dutch TLD. +1 to you, Sir! –  Janne Pikkarainen Jul 17 '12 at 6:42
nl, now fancy that .. +1 for a cmd i never knew about –  The Unix Janitor Jul 17 '12 at 11:46
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.