Commands tagged ping (47)

  • Works on any machine with nmap installed. Previous version does not work on machines without "seq". Also works on subnets of any size. Show Sample Output

    nmap -sP
    sdadh01 · 2010-06-05 14:48:37 2
  • pings a server once per second, and beeps when the server is unreachable. Basically the opposite of: ping -a which would beep when a server IS reachable. You could also substitute beep with any command, which makes this a powerful alternative to ping -a: while true; do [ "$(ping -c1W1w1 2>/dev/null | awk '/received/ {print $4}')" = 1 ] && date || echo 'server is down!'; sleep 1; done which would output the date and time every sec until the ping failed, in which case it would echo. Notes: Requires beep package. May need to run as root (beep uses the system speaker) Tested on Ubuntu which doesn't have beep out of the box... sudo apt-get install beep

    while true; do [ "$(ping -c1W1w1 | awk '/received/ {print $4}')" != 1 ] && beep; sleep 1; done
    sudopeople · 2009-03-31 20:47:56 4
  • Usefull for when you don't have nmap and need to find a missing host. Pings all addresses from to, modify for your subnet. Timeout set to 1 sec for speed, if running over a slow connection you should raise that to avoid missing replies. This will clean up the junk, leaving just the IP address: for i in {1..254}; do ping -c 1 -W 1 10.1.1.$i | grep 'from' | cut -d' ' -f 4 | tr -d ':'; done Show Sample Output

    for i in {1..254}; do ping -c 1 -W 1 10.1.1.$i | grep 'from'; done
    SuperJediWombat · 2010-04-07 16:57:53 0
  • This command uses ping to get the routers' IP addresses to the destination host as traceroute does. If you know what I mean..

    for i in {1..30}; do ping -t $i -c 1; done | grep "Time to live exceeded"
    6bc98f7f · 2012-02-19 13:37:04 4
  • PING parameters c 1 limits to 1 pinging attempt q makes the command quiet (or silent mode) /dev/null 2>&1 is to remove the display && echo ONLINE is executed if previous command is successful (return value 0) || echo OFFLINE is executed otherwise (return value of 1 if unreachable or 2 if you're offline yourself). I personally use this command as an alias with a predefined machine name but there are at least 2 improvements that may be done. Asking for the machine name or IP Escaping the output so that it displays ONLINE in green and OFFLINE in red (for instance).

    ping -c 1 -q MACHINE_IP_OR_NAME >/dev/null 2>&1 && echo ONLINE || echo OFFLINE
    UnixNeko · 2012-02-09 06:30:55 7
  • Joker wants an email if the Brand X server is down. Set a cron job for every 5 mins with this line and he gets an email when/if a ping takes longer than 3 seconds. Show Sample Output

    ping -q -c1 -w3 2&>1 /dev/null || echo ping failed | mail -ne -s'Server unavailable'
    mccalni · 2009-10-13 14:13:04 7
  • When run on a mac, this command will bring up a dialog box in the Terminal when server HOSTNAME first responds to a ping.

    ping -o -i 30 HOSTNAME && osascript -e 'tell app "Terminal" to display dialog "Server is up" buttons "It?s about time" default button 1'
    neologism · 2009-08-03 16:06:57 1
  • It really disables all ICMP responses not only the ping one. If you want to enable it you can use: sudo -s "echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all"

    sudo -s "echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all"
    sliceoflinux · 2010-06-22 19:16:43 0
  • Audio acknowledgement for host availability. When running the command from a Linux systems, you can use "festival" or "espeak" instead of "say".

    Mac OSX: ping -oc 30 > /dev/null && say "Google name server is up" || say "This host is down"
    raulyca · 2014-08-01 15:44:57 0
  • Ping sweep without NMAP

    for i in `seq 1 255`; do ping -c 1 10.10.10.$i | tr \\n ' ' | awk '/1 received/ {print $2}'; done
    hemanth · 2009-08-22 09:34:27 9
  • Waits for all pings to complete and returns ip with mac address

    (prefix="10.59.21" && for i in `seq 254`; do (sleep 0.5 && ping -c1 -w1 $prefix.$i &> /dev/null && arp -n | awk ' /'$prefix'.'$i' / { print $1 " " $3 } ') & done; wait)
    smoky · 2014-04-02 11:20:57 0
  • After this, just type: beepwhenup You need to install "beep" before this would make the beep sound. Save it in your .profile if you want to use it later WARNING: this command won't exit until it is successful. You won't be able to CONTROL+C out of it.

    beepwhenup () { echo 'Enter host you want to ping:'; read PHOST; if [[ "$PHOST" == "" ]]; then exit; fi; while true; do ping -c1 -W2 $PHOST 2>&1 >/dev/null; if [[ "$?" == "0" ]]; then for j in $(seq 1 4); do beep; done; ping -c1 $PHOST; break; fi; done; }
    linuxrawkstar · 2009-09-24 18:11:10 4
  • Alternative to the ping check if your firewall blocks ping. Uses curl to get the landing page silently, or fail with an error code. You can probably do this with wget as well. Show Sample Output

    curl -fs 2&>1 > /dev/null || echo ping failed | mail -ne -s'Server unavailable'
    mccalni · 2009-10-23 14:29:06 1
  • For some reason the 2&>1 does not work for me, but the shorter stdout/stderr redirection >& works perfectly (Ubuntu 10.04).

    ping -q -c1 -w3 >& /dev/null || echo ping failed | mail -ne -s'Server unavailable'
    brainstorm · 2010-09-08 12:19:29 1

  • 2
    ping HOSTNAME | while read pong; do echo "$(date): $pong"; done
    sammcj · 2011-09-07 02:03:19 0
  • Cleaner with a mailto assignment in crontab (if the command fails you get an email): 10,30,50 * * * * ping -q -c1 -w3 >/dev/null

    10,30,50 * * * * ping -c1 -w3 >/dev/null
    bashrc · 2012-02-06 14:54:15 0
  • Nasty perl one-liner that provides a sparkline of ping times. If you want a different history than the last 30, just put that value in. It (ab)uses unicode to draw the bars, inspired by . It's not the most bug-free piece of code, but what it lacks in robustness it makes up for in capability. :) If anyone has any ideas on how to make it more compact or better, I'd love to hear them. I included a ping to google in the command just as an example (and burned up 10 chars doing it!). You should use it with: $ ping | $SPARKLINE_PING_COMMAND Show Sample Output

    ping|perl -ne'$|=/e=(\S+)/||next;(push@_,$1)>30&&shift@_;print"\r",(map{"\xe2\x96".chr(128+7*$_/(sort{$b<=>$a}@_)[0])." "}@_),"$1ms"'
    bartgrantham · 2012-07-06 22:42:06 0

  • 2
    nmap -sn
    pdxdoughnut · 2014-01-28 23:32:18 0
  • Will report back IP address's of all hosts that are UP. Show Sample Output

    fping -ga 2> /dev/null
    netaxiz · 2014-01-31 19:19:19 0
  • This allows for sleeping in between pings. Also, espeak needs to be installed.

    speakwhenup() { [ "$1" ] && PHOST="$1" || return 1; until ping -c1 -W2 $PHOST >/dev/null 2>&1; do sleep 5s; done; espeak "$PHOST is up" >/dev/null 2>&1; }
    aguslr · 2014-11-26 10:22:18 0
  • This command only check the network connection from given eth. This is very useful if you are using more then one interface in your server or laptop. Show Sample Output

    ping -I eth0
    octopus · 2010-04-12 06:25:07 0
  • This is like ping -a, but it does the opposite. It alerts you if the network is down, not up. Note that the beep will be from the speaker on the server, not from your terminal. Once a second, this script checks if the Internet is accessible and beeps if it is not. I define the Net as being "UP", if I can ping Google's public DNS server (, but of course you could pick a different static IP address. I redirect the beep to /dev/console so that I can run this in the background from /etc/rc.local. Of course, doing that requires that the script is run by a UID or GID that has write permissions to /dev/console (usually only root). Question: I am not sure if the -W1 flag works under BSD. I have only tested this under GNU/Linux using ping from iputils. If anybody knows how portable -W is, please post a comment.

    while :; do ping -W1 -c1 -n > /dev/null || tput bel > /dev/console; sleep 1; done
    hackerb9 · 2010-09-24 06:34:12 2
  • I have used single packet, and in a silent mode with no display of ping stats. This is with color and UI improvement to the It is as per the enhancements suggested. Show Sample Output

    echo -n "IP Address or Machine Name: "; read IP; ping -c 1 -q $IP >/dev/null 2>&1 && echo -e "\e[00;32mOnline\e[00m" || echo -e "\e[00;31mOffline\e[00m"
    crlf · 2012-02-09 07:00:03 1

  • 0
    for ip in `seq 1 255`; do ping -c 1 192.168.1.$ip ; done | grep ttl
    takeshin · 2010-06-05 13:15:06 1
  • If you're very busy and don't want to wait for a ping response, use it. This command will be waiting for a successful ping response, to play a sound file to warn you that the target host is available.

    continuar=true; while $continuar; do if ping -c 3 [target_IP_address] 2>&1> /dev/null ; then mplayer [sound_file]; continuar=false; break; fi; done
    mack · 2011-04-25 21:44:05 5
  •  1 2 > 

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Check These Out

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Compare a remote dir with a local dir
You can compare directories on two different remote hosts as well: $ diff -y

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Create a mirror of a local folder, on a remote server
Create a exact mirror of the local folder "/root/files", on remote server 'remote_server' using SSH command (listening on port 22) (all files & folders on destination server/folder will be deleted)

Vim: Switch from Horizontal split to Vertical split
This allows to switch from horizontal to vertical split, putting the current buffer on the right side of the vertical split. To put it on the right use ^W-H. In a similar way, to switch from Vertical to Horizontal, do ^W-J (for bottom) and ^W-K (for top), but you vimers all guessed that one already :P

Top 10 Memory Processes
It displays the top 10 processes sorted by memory usage

Colored SVN diff
Simple way to achieve a colored SVN diff

Install pip with Proxy
Installs pip packages defining a proxy

tmux start new session with title and execute command
in this examp start htop command in tmux session over the shell cosole and set title for the tmux without doing it manuelly in tmux

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: