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 tagged geoip from sorted by
Terminal - Commands tagged geoip - 16 results
curl ipinfo.io/<ipaddress>
curl ipinfo.io
2013-10-31 05:16:47
User: coderholic
0

Get your ip address, hostname, ASN and geolocation information. If you want just one field as a text response you can also get that,eg curl ipinfo.io/ip

cat /var/log/nginx/access.log | grep -oe '^[0-9.]\+' | perl -ne 'system("geoiplookup $_")' | grep -v found | grep -oe ', [A-Za-z ]\+$' | sort | uniq -c | sort -n
2012-05-08 13:28:25
User: theist
Functions: cat grep perl sort uniq
Tags: sort uniq geoip
-1

Per country GET report, based on access log. Easy to transform to unique IP

lynx -dump http://www.ip2location.com/ | sed -n '/^ *Field Name *Value *$/,/^ *\[_\] *Mobile .*Carrier.*name/p'
curl ip.nu
curl -s ifconfig.me|tee >(xargs geoiplookup)
2012-02-09 20:30:26
Functions: tee xargs
Tags: tee curl geoip
0

Show external IP and geolocation information.

Primary feature is the use of tee to echo IP _and_ send to geoiplookup command...Use IP as input for as many commands as you want with more >( [command] )

Thanks to http://www.commandlinefu.com/commands/view/6334/

Requires MaxMind DB and geoiplookup tool.

Sample output has IP obfuscated on first line, lines 2-4 from having MaxMind Country && MaxMind City DBs installed

curl http://my-ip.cc/host.json
2011-09-01 00:31:49
User: samleb
0

JSON version.

Additionally it may give your geolocation if it's known by hostip.info

curl http://my-ip.cc/host.xml
2011-09-01 00:30:03
User: samleb
-1

XML version.

Additionally it may give your geolocation if it's known by hostip.info

curl http://my-ip.cc/host.txt
2011-09-01 00:28:49
User: samleb
-1

Additionally it may give your geolocation if it's known by hostip.info

for IP in `cat ip.txt|awk -F: '{print $1}'`; do geoiplookup -f /usr/local/share/GeoIP/GeoIP.dat $IP|awk -F, '{print $2}'>>out.txt; done; paste -d ":" ip.txt out.txt>zoom.txt
2011-08-05 09:26:17
User: woben2
Functions: awk paste
Tags: geoip
-1

take a list of IP:PORT and output IP:PORT:COUNTRY

geoip() { lynx -dump "http://api.hostip.info/get_html.php?ip=$1&position=true"; }
0

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

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
0

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

curl -s www.google.com/ig/api?weather=$(curl -s api.hostip.info/get_html.php?ip=$(curl -s icanhazip.com) | sed -e'1d;3d' -e's/C.*: \(.*\)/\1/' -e's/ /%20/g' -e"s/'/%27/g") | sed 's|.*<t.*f data="\([^"]*\)"/>.*|\1\n|'
2010-02-14 19:44:54
User: o0110o
Functions: sed
0

Check your local temperature based on geolocation.

curl -s http://www.google.com/ig/api?weather=$(curl -s "http://api.hostip.info/get_html.php?ip=$(curl -s icanhazip.com)" | grep City | sed 's/City: \(.*\)/\1/' | sed 's/ /%20/g' | sed "s/'/%27/g") | sed 's|.*<temp_f data="\([^"]*\)"/>.*|\1\n|'
geoiplookup www.commandlinefu.com
2009-11-15 11:56:19
User: Sunng
0

geoip from maxmind

try to get the small utility via:

apt-get install geoip

geo(){ curl -s "http://www.geody.com/geoip.php?ip=$(dig +short $1)"| sed '/^IP:/!d;s/<[^>][^>]*>//g'; }
2009-11-12 17:14:09
User: dennisw
Functions: sed
1

A function that takes a domain name as an argument