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 ip address from sorted by
Terminal - Commands tagged ip address - 101 results
$ wget --no-check-certificate -q checkip.dyndns.org -O index.html && cat index.html|cut -d ' ' -f 6 | cut -d '<' -f 1
2014-05-12 07:10:29
User: Superkikim
Functions: cat cut wget
0

This is the command line I use to get my IP address in order to update my zoneedit account. Full script on my blog http://akim.sissaoui.com/linux-attitude/script-de-mise-a-jour-ddns-zoneedit-com-en-bashsh/

sudo tcpdump -i wlan0 -n ip | awk '{ print gensub(/(.*)\..*/,"\\1","g",$3), $4, gensub(/(.*)\..*/,"\\1","g",$5) }' | awk -F " > " '{print $1"\n"$2}'
curl ip.telize.com
2014-02-04 12:25:52
User: fcambus
0

ip.telize.com (Listen on both IPv4 and IPv6)

ip4.telize.com (Listen on IPv4 only)

ip6.telize.com (Listen on IPv6 only)

More information on : http://www.telize.com

sed -n 's/.*\(\(\(^\| \)[0-9]\{1,3\}\.\)\{1\}\([0-9]\{1,3\}\.\)\{2\}[0-9]\{1,3\}\) .*/\1/gp'
2014-01-29 23:18:14
User: smkr
Functions: sed
Tags: sed ip address
0

looks for IPs at the beginning of the line or prefixed by a space

cls && ipconfig | findstr -R "[ IPv4 | adapter ]"
cls && ipconfig | findstr -R "[ IPv4 | adapter ]"
cls && ipconfig | find "IPv4"
2013-12-03 13:08:01
User: dizzi90
Functions: find
2

May be useful to get user's ip address over the phone, as users struggle to read through a long ipconfig result.

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

wget http://ipecho.net/plain -O - -q ; echo
2013-10-02 21:18:40
Functions: wget
1

Returns your external IP address to the command line using only wget

dig +short <domain>
dig +short google.com
host example.com | head -1 | awk '{print $4}'
nslookup www.example.com | tail -2 | head -1 | awk '{print $2}'
2013-09-05 20:26:45
User: wsams
Functions: awk head nslookup tail
1

I'm not sure how reliable this command is, but it works for my needs. Here's also a variant using grep.

nslookup www.example.com | grep "^Address: " | awk '{print $2}'

for i in `ip addr show dev eth1 | grep inet | awk '{print $2}' | cut -d/ -f1`; do echo -n $i; echo -en '\t'; host $i | awk '{print $5}'; done
curl -s http://wtfismyip.com/text
2013-06-27 10:53:54
User: m3adow
0

Plain Text Ip Output, independent of Layout change.

curl l2.io/ip
curl http://ipecho.net/plain
curl -s mi-ip.net | grep '"ip"' | cut -f2 -d ">" | egrep -o '[0-9.]+'
2012-10-15 16:48:20
User: dragonauta
Functions: cut egrep grep
0

looks at html for "ip" (it's a CSS class), then a little of cut and egrep to get IPv4 address.

I use this oneliner into conky.

ip route get 8.8.8.8 2>/dev/null|grep -Eo 'src [0-9.]+'|grep -Eo '[0-9.]+'
2012-10-14 02:06:13
User: intangible
Functions: get grep route
2

Instead of hard-coding in a check to scrape info from ifconfig based on a specific interface, do it in a more portable way.

This works really well if you switch between wired, wireless, bluetooth or even VPN connections. You can get your current IP in a script (since it'll be something like tun0 instead of eth0 or wlan1).

This uses a well known public ip address 8.8.8.8, but it doesn't actually connect to it, it just shows you the route it would take.

ip -o -4 a s
2012-09-19 10:59:05
User: ioggstream
4

Short list of all ip.

Shows even the newly supported multiple ip address on the same interface (see eth1).

For ipv6 use -6

curl icanhazip.com
curl queip.tk/ip
lsof -p `pidof pidgin` | awk '{ print $9 }'|egrep `hostname` | grep -o ">[^:]\+:" | tr -d ":>" | while read line; do host $line; done;
dig o-o.myaddr.l.google.com @ns1.google.com txt +short
2012-07-30 06:54:57
User: quentin
Functions: dig
0

Asks Google what your current IP address is. Bonus: Remove "@ns1.google.com" and you will instead get the IP address of your DNS server.