Hide

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using ping from sorted by
Terminal - Commands using ping - 63 results
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 127.0.0.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
2

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
0

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
0

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.

ping 8.8.8.8
2011-02-18 19:51:36
User: petrus
Functions: ping
0

8.8.8.8 and 8.8.4.4 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
-1

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
4

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 8.8.8.8 > /dev/null || tput bel > /dev/console; sleep 1; done
2010-09-24 06:34:12
User: hackerb9
Functions: ping sleep tput
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 (8.8.8.8), 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
2

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
-3

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
-9

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 10.1.1.0/24 | awk '/00:1b:11:dc:a9:65/ {print $1}'`
2010-05-11 13:12:43
User: voyeg3r
Functions: awk ping
4

# first install arp-scan if not have it

arp-scan 10.1.1.0/24 .... 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
1

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
-2

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
13

Usefull for when you don't have nmap and need to find a missing host.

Pings all addresses from 10.1.1.1 to 10.1.1.254, 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

sudo ping -f -s 56500 192.168.1.100
2010-01-27 17:42:33
User: alamati
Functions: ping sudo
-3

A ping flood is a simple DoS attack where the attacker overwhelms the victim with ICMP Echo Request (ping) packets. It only succeeds if the attacker has more bandwidth than the victim (for instance an attacker with a DSL line and the victim on a dial-up modem).

In this command replace 192.168.1.100 with victim IP address.

ping www.facebook.com
curl -fs brandx.jp.sme 2&>1 > /dev/null || echo brandx.jp.sme ping failed | mail -ne -s'Server unavailable' joker@jp.co.uk
2009-10-23 14:29:06
User: mccalni
Functions: echo mail ping
Tags: bash ping curl mail
2

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.