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 - 100 results
ifconfig | sed -n 's/.*inet addr:\([0-9.]\+\)\s.*/\1/p'
ip -f inet a | awk '/inet / { print $2 }'
2012-07-18 15:13:10
User: BorneBjoern
Functions: awk
Tags: awk IP ip address
2

gives u each configured IP in a seperate line.

nmap -T4 -sn 192.168.1.0/24
2012-06-19 17:07:24
User: drewbled
0

Does a ping scan on the local subnet and returns the IPs that are up

curl ifconfig.me/all
2012-05-16 18:22:28
User: pykler
9

Gets all kind of info, ifconfig.me rocks ...

for just the ip addess you can use ifconfig.me or ifconfig.me/ip

lynx -dump http://www.ip2location.com/ | sed -n '/^ *Field Name *Value *$/,/^ *\[_\] *Mobile .*Carrier.*name/p'
lynx -dump ip.nu
curl ip.nu
curl ifconfig.me
echo -n $(curl -Ss http://icanhazip.com) | xclip
2012-02-17 16:58:40
User: red_five
Functions: echo
0

Gets the IP and sticks it into the middle-mouse-click buffer

wget http://icanhazip.com -qO-
w3m mon-ip.com -dump|grep -Eo "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"|uniq|xclip -selection clipboard
wget ifconfig.me/ip -q -O -
curl icanhazip.com
cat /var/log/auth.log | grep -i "pam_unix(sshd:auth): authentication failure;" | cut -d' ' -f14,15 | cut -d= -f2 | sort | uniq
2011-10-25 04:58:09
User: JohnQUnknown
Functions: cat cut grep sort
0

This command shows a sorted list of the IP addresses from which there have been authentication errors via SSH (possible script kiddies trying to gain access to your server), it eliminates duplicates so it's easier to read, but you can remove the "uniq" command at the end, or even do a "uniq -c" to have a count of how many times each IP address shows in the log (the path to the log may vary from system to system)

wget -O - -q http://checkip.dyndns.org/ | cut -d':' -f2 | cut -d'<' -f1| cut -c2-
2011-09-17 13:42:01
User: ztank1013
Functions: cut wget
-2

This is just a "cut" addicted variant of the previous unixmonkey24730 command...

wget http://checkip.dyndns.org/ -q -O - | grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>'
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

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.

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

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
3

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

host google.com|awk '{print $NF}'