How do I terminate a 'Ping' without closing the command terminal window?

When I use the 'Ping' command in a terminal window, how do I terminate the ping? I have pinged my router (192.168.1.1) and the results have displayed in the terminal window, but the program keeps running with no indication as to how to terminate.

I can end the command by closing the command terminal window, but I would rather keep it open so I can compare pings with different addresses.

Ubuntu 14.04 LTS


There are three options:

  • Manually interrupt the ping command using Ctrl+C, as described in @steeldriver's answer.

  • Use ping's "count" option (-c COUNT) to send exactly COUNT pings and then terminate automatically, as described in @bodhi.zazen's answer.

  • Use ping's "deadline" option (-w DEADLINE) to run for exactly DEADLINE seconds and then terminate automatically.


Of course you can combine the three options. If you pass both a "count" and a "deadline" option, ping will terminate as soon as the first event occurs. And Ctrl+C works always anyway.

Here's an example with a "count" of maximal 10 pings and a "deadline" of 5 seconds, but which got terminated manually using Ctrl+C after 3 pings (^C):

$ ping -c 10 -w 5 askubuntu.com
PING askubuntu.com (104.16.110.188) 56(84) bytes of data.
64 bytes from 104.16.110.188: icmp_seq=1 ttl=56 time=54.6 ms
64 bytes from 104.16.110.188: icmp_seq=2 ttl=56 time=52.5 ms
64 bytes from 104.16.110.188: icmp_seq=3 ttl=56 time=54.0 ms
^C
--- askubuntu.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 52.582/53.733/54.611/0.850 ms

You can use Ctrl+C to send a SIGINT (interrupt signal) to the ping process - see Unix signals