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.

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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Get the IP address of a machine. Just the IP, no junk.

Terminal - Get the IP address of a machine. Just the IP, no junk.
/sbin/ifconfig -a | awk '/(cast)/ { print $2 }' | cut -d':' -f2 | head -1
2009-04-15 06:44:18
User: d4n3sh
Functions: awk cut head
Get the IP address of a machine. Just the IP, no junk.


There are 2 alternatives - vote for the best!

Terminal - Alternatives
ip -o -4 addr show | awk -F '[ /]+' '/global/ {print $4}'
2013-04-09 16:34:39
User: atoponce
Functions: awk

Why use many different utilities all piped together, when you only need two?

host `hostname` | rev | cut -d' ' f1 | rev
2014-10-01 18:55:05
Functions: cut host rev

Gives the DNS listed IP for the host you're on... or replace `hostname` with any other host

ifconfig -a | awk '/Bcast/{print $2}' | cut -c 5-19
ifdata -pN eth0
2013-04-12 15:05:36

No junk, no pipe, one command, no subcommand - KISS

ifconfig -a | awk '/Bcast/{print $2}' | cut -c 5-19

Know a better way?

If you can do better, submit your command here.

What others think

Nice, I use this:

/sbin/ifconfig -a |sed -n 's/.*addr:\(.*\)[ ]*Bcast.*/\1/p'
Comment by elzapp 399 weeks and 2 days ago

awful !

Comment by megerdin 399 weeks and 2 days ago

My Linksys router running Freewrt doesn't have ifconfig, and ip addr show includes CIDR notation for some annoying reason. So, I use this to get my external IP (not mine, something I found googling):

ip -o addr show eth0 | awk '$3 == "inet" {split($4,i,"/"); print i[1]; exit}'

Comment by sud0er 399 weeks and 2 days ago

Thanks elzapp,

way better :D

Comment by d4n3sh 399 weeks and 1 day ago

Sorry, I feel bad for voting you down after all the effort you put into this one, but you just need to use "hostname -i"

Comment by kFiddle 399 weeks ago

voted down because:

a) It's already in the archive


b) It does not handle the situation when there are multiple network interfaces active.

Assuming that the default route is via the network interface of interest:

/sbin/ifconfig $(netstat -rn | grep "^" | awk '{print $8}') | awk -F: '/inet addr/ {printf("%s\n",substr($2,1,index($2," "))) }'

Comment by mpb 398 weeks and 5 days ago
/sbin/ifconfig -a |sed -n 's/.*addr:\(.*\)[ ]*Bcast.*/\1/p'

This doesn`t work for me.

- debian lenny

- GNU sed Version 4.1.5

Comment by P17 396 weeks and 2 days ago

@kFiddle - nice one, but

hostname -i

returns for me - better is recommended

hostname -I

with uppercase I - gives me IPv6 too

Comment by sashametro 189 weeks and 4 days ago

Your point of view

You must be signed in to comment.