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 tagged ip address from sorted by
Terminal - Commands tagged ip address - 105 results
geoip() { lynx -dump "http://api.hostip.info/get_html.php?ip=$1&position=true"; }

Defines a function to geolocate a given IP address; if none supplied, will default to your external IP address.

curl ifconfig.me
curl http://ifconfig.me/ip
2010-12-21 18:57:32
User: VxJasonxV

Relies on ifconfig.me functioning. It's about as easy as it gets, and memorable to old geeks too.

getent hosts google.com | awk '{print $1}'
2010-11-03 12:02:05
User: depesz
Functions: awk getent

has the benefit of being a bit more cross-platform.

host google.com|awk '{print $NF}'
dig hostname a +short
gethostip -d hostname
host foo.com|grep " has address "|cut -d" " -f4
2010-10-29 17:01:37
User: dinomite
Functions: cut grep host

Get just the IP address for a given hostname. For best results, make this a function in your shell rc file so that it can be used for things like traceroute:

Titus:~$ traceroute `getip foo.com`

traceroute to (, 64 hops max, 52 byte packets

geoiplookup <ipadress>
2010-10-13 09:19:17
User: houghi

GeoIP Needs to be installed. Can be done from some distro's or via MaxMind.com for free. There even is a free city database availabble. If the GeoLiteCity is downloaded and installed it will also find more information

geoiplookup -f /var/lib/GeoIP/GeoLiteCity.dat commandlinefu.com

GeoIP City Edition, Rev 1: US, NJ, Absecon, 08201, 39.420898, -74.497704, 504, 609

ip2loc() { wget -qO - www.ip2location.com/$1 | grep "<span id=\"dgLookup__ctl2_lblICountry\">" | sed 's/<[^>]*>//g; s/^[\t]*//; s/&quot;/"/g; s/</</g; s/>/>/g; s/&amp;/\&/g'; }
2010-10-13 00:19:35
User: bkuri
Functions: grep sed wget

Grabs the ip2location site and removes everything but the span tag containing the country value. Place it inside your .bashrc or .bash_aliases file.

echo 00:16:3e$(gethostip | awk '{ print tolower(substr($3,3)) }' |sed 's/.\{2\}/:&/g' )
2010-09-23 16:46:21
User: chwilk
Functions: awk echo sed

Useful for creating MAC addresses for virtual machines on a subnet. 00:16:3e is a standard Xen OID, change as needed.

wget -qO- ifconfig.me/ip
2010-08-05 12:04:43
User: glaudiston
Functions: wget
Tags: ip address

alternative to

curl ifconfig.me

for those that don't have curl

dig @ myip.opendns.com
2010-08-01 13:58:54
User: CodSpirit
Functions: dig
Tags: ip address

Very effective, use only DNS protocol. The @ part is optional if you already set opendns servers as default ns servers.

curl ifconfig.me
wget --quiet -O - checkip.dyndns.org | sed -e 's/[^:]*: //' -e 's/<.*$//'
2010-08-01 13:36:08
User: berkes
Functions: sed wget
Tags: ip address

Wgets "whatismyip" from checkip.dyndns.org and filters out the actual IP-adress. Usefull when you quickly need to find the outward facting IP-address of your current location.

nmap -v -sP
2010-07-14 19:53:02
User: anapsix

nmap for windows and other platforms is available on developer's site: http://nmap.org/download.html

nmap is robust tool with many options and has various output modes - is the best (imho) tool out there..

from nmap 5.21 man page:

-oN/-oX/-oS/-oG : Output scan in normal, XML, s|

sudo arp-scan -I eth0
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.

wget -qO- icanhazip.com
2010-06-24 03:49:14
Functions: wget

Curl is not installed by default on many common distros anymore. wget always is :)

wget -qO- ifconfig.me/ip
echo -e "GET /ip HTTP/1.0\nUser-Agent: netcat\nHOST: ifconfig.me\n\n" | nc ifconfig.me 80 | sed -n '/^[0-9]/p'
2010-06-16 19:08:05
User: putnamhill
Functions: echo sed

Here's a version that uses netcat (although I'd much rather use curl!).

lynx --dump icanhazip.com
curl icanhazip.com
2010-06-14 18:47:11
User: pykler

With a lolcat favicon if you access it from your browser

for i in 192.168.1.{1..254} ; do if ping -c1 -w1 $i &>/dev/null; then echo $i alive; fi; done
nmap -sP
2010-06-05 14:48:37
User: sdadh01

Works on any machine with nmap installed. Previous version does not work on machines without "seq".

Also works on subnets of any size.

for ip in `seq 1 255`; do ping -c 1 192.168.1.$ip ; done | grep ttl