commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
Shows the interface and the ip-address
There are 4 alternatives - vote for the best!
Shows only IP-addresses of ifconfig except 127.0.0.0/8.
I fixed the script to work on more systems and configs
/inet/!d; #grep inet
/127.0/d; # grep -v 127.0
/dr:\s/d; # grep -v dr:
s/^.*:\(.*\)B.*$/\1/ # remove everything exept between : and B
This also works on non-Linux machines. If you have GNU sed you can do it more elegantly:
ifconfig | sed -n 's/^\s*inet \(addr:\)\?\([^\s]*\) .*/\2/;T;/^127\./d;p'
This is what we use.
You can grep -v 127.0.0.1 if you wish.
short enough to be tweetable
If you can do better, submit your command here.
You must be signed in to comment.