What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.

If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Universal configuration monitoring and system of record for IT.

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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Commands using ping from sorted by
Terminal - Commands using ping - 65 results
ping -qc 10 server.tld | awk -F/ '/^rtt/ {print $5}'
2011-10-12 21:07:06
User: atoponce
Functions: awk ping
Tags: awk ping

Quick and dirty one-liner to get the average ping(1) time from a server.

until ping -c1 ADDRESS;do true;done;zenity --warning --text "ADDRESS is back"
2011-09-26 18:51:38
User: marcusrp
Functions: ping
Tags: Network zenity

I'd rather this one on Gnome, as I'm used to be listening some music while working. I've even created a bash function which receives ADDRESS as parameter.

echo "command lines" | rev | cut -c 2- | rev
2011-09-21 11:27:52
User: ztank1013
Functions: cut echo ping rev
Tags: sed awk cut rev

In case sed and awk are not available you may use this to remove the last character from a string with "rev" and "cut".

ping HOSTNAME | while read pong; do echo "$(date): $pong"; done
for i in `seq 254`;do ping -c 1 192.168.10.$i > /dev/null && echo "$i is up"||echo "$i is down";done
while ping -c 1 > /dev/null; do acpi -t -f | while read tem; do notify-send "$tem"; done; sleep 300; done
2011-07-02 06:47:25
User: c0de
Functions: acpi ping read sleep

works best in a shell script run at startup. It will ping localhost once and output to null, after it does that, acpi is called for temperature in fahrenheit and piped through to another loop that feeds notify-send for a tooltip. After waiting five minutes, it will start over.

ping -a IP-ADDRESS
2011-04-28 13:51:12
User: markussesser
Functions: ping

pcspkr have to be enabled!

modprobe pcspkr

xset b on

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
2011-04-25 21:44:05
User: mack
Functions: ping

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.

2011-02-18 19:51:36
User: petrus
Functions: ping
0 and are two Google public DNS.

As their address is really simple, it's easy to use this command to test if Internet is reachable.

Beware of large corporate networks however, that may use this address on router's loopbacks interfaces.

ping -q -c 1 www.google.com|awk -F/ 'END{print $5}'
ping -q -c 1 www.google.com|tail -1|cut -d/ -f5
ping -c 1 www.google.com | /usr/bin/awk '{print $7}' | /usr/bin/awk 'NR > 1' | /usr/bin/awk 'NR < 2' | /usr/bin/awk -F"=" '{print $2}'
2010-12-15 08:50:52
User: ackers
Functions: ping

Does one ping to a URL or host, and echo out just the response time. I use this on, with MRTG to monitor the connections to various hosts.

nohup ping -i1 www.google.com &
ping -i1 www.google.com &> /dev/null & disown
2010-11-09 11:22:57
User: strzel_a
Functions: ping

Continue to execute the command in background even though quitting the shell.

ping -c 1 google.com | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
while :; do ping -W1 -c1 -n > /dev/null || tput bel > /dev/console; sleep 1; done
2010-09-24 06:34:12
User: hackerb9
Functions: ping sleep tput

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.

ping -q -c1 -w3 server.example.com >& /dev/null || echo server.example.com ping failed | mail -ne -s'Server unavailable' admin@example.com
2010-09-08 12:19:29
User: brainstorm
Functions: echo mail ping
Tags: bash ping mail

For some reason the 2&>1 does not work for me, but the shorter stdout/stderr redirection >& works perfectly (Ubuntu 10.04).

sudo ping -f -c 999 -s 4500 target.com
2010-07-11 16:38:44
User: gunslinger_
Functions: ping sudo
Tags: ping

sending packet by ping

if sending more high packet root needed...

FOR /L %i IN (1,1,254) DO ping -n 1 10.254.254.%i | FIND /i "Reply">> c:\ipaddresses.txt
2010-06-29 21:02:21
Functions: ping

documents all active ips on a subnet and saves to txt file.

for i in 192.168.1.{1..254} ; do if ping -c1 -w1 $i &>/dev/null; then echo $i alive; fi; done
for ip in `seq 1 255`; do ping -c 1 192.168.1.$ip ; done | grep ttl
ping -c 2 `arp-scan | awk '/00:1b:11:dc:a9:65/ {print $1}'`
2010-05-11 13:12:43
User: voyeg3r
Functions: awk ping

# first install arp-scan if not have it

arp-scan .... show ip+mac in localnet

awk '/00:1b:11:dc:a9:65/ {print $1}' .... get ip associated with MAC

` backtick make do command substitution passing ip to command ping

ping -I eth0 www.yahoo.com
2010-04-12 06:25:07
User: octopus
Functions: ping

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.

prefix="10.0.0" && for i in `seq 25`; do ping -c 1 $prefix.$i &> /dev/null && echo "Answer from: $prefix.$i" ; done
2010-04-07 17:17:21
User: xeor
Functions: echo ping
Tags: ping

Not really an easier solution. But an example using && for (if last command returned 0). You can use || for (if last command returned other than 0)..

for i in {1..254}; do ping -c 1 -W 1 10.1.1.$i | grep 'from'; done
2010-04-07 16:57:53
Functions: grep ping
Tags: ping

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