ifconfig -u|grep -v inet6|grep -v media| grep -v lladdr|grep -v ether|grep -v status|sed "s/flags=.*//"|sed "s/^.*inet \(.*\) netmask.*$/\1/"|sed "s/^\([elfv]\)/#\1/"|tr -d '\n'|tr '#' '\n' && echo
I just want a simple display of the interfaces on my system and their IPs. I was in a rush and came up with that disgusting line. On the one hand it demonstrates the power of Unix, on the other hand it demonstrates the problems with it. So, dear interwebs, please provide me with (in order of preference):
- A better way of doing it (I'm thinking sysctl, [I'm on a Mac])
- The right command line magic to get better greppable output from ifconfig
- An optimised command line, specifically:
- How can you combine the multiple "grep -v" commands?
- How can I combine the sed & tr commands?
Failing that, here's a command you too can use to give you a fragile list of interfaces and their ipv4 addresses. I've embedded it on my desktop with GeekTool (OSX). It makes the FW logs also embedded on my desktop make more sense :)
UPDATE: I love you my fellow Geeks. The winning solution is from Craig Balding via twitter, who put us all to shame with the ridiculously simple piece of cli kung-fu that is:
ifconfig|awk '/mtu/ {nic=$1} /inet / {print nic " " $2}'
Continue reading "Simple IF: IP list - the Unix way"