使用行号进行 ping

使用行号进行 ping

简单问题:如何ping在 Linux 上显示输出中的行号?

我是说:

1 64 bytes from www.site.com (2.7.1.1): icmp_req=1 ttl=247 time=17.9 ms
2 64 bytes from www.site.com (2.7.1.1): icmp_req=2 ttl=247 time=16.1 ms
3 64 bytes from www.site.com (2.7.1.1): icmp_req=3 ttl=247 time=16.1 ms

答案1

nl命令将行号添加到其输入中,以便您可以通过管道将输出传输pingnl

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

相关内容