Show me just the ip address

showip() { nmcli connection show $1|grep ipv4.addresses|awk '{print $2}' ; }
Sometimes it's useful to output just the ip address. Or some other information, changing the "ipv4.addresses" in command. The power of awk! Show all possible "greps" with nmcli connection show [yourInterfaceNameHere]
Sample Output
$ showip eth0
$ showip eth1

By: nnsense
2015-05-13 16:24:28

These Might Interest You

  • This doesn't make any assumptions about your IP address and prints out one IP address per line if you have multiple network interfaces. Show Sample Output

    ifconfig | sed '/.*addr.*Bcast.*/ ! d'| sed 's/.*addr:\([0-9\.]*\).*/\1/'
    Haegin · 2010-03-26 08:13:13 0
  • From 'man netstat' "netstat -i | -I interface [-abdnt] [-f address_family] [-M core] [-N system] Show the state of all network interfaces or a single interface which have been auto-configured (interfaces statically configured into a system, but not located at boot time are not shown). An asterisk (``*'') after an interface name indicates that the interface is ``down''. If -a is also present, multicast addresses currently in use are shown for each Ethernet interface and for each IP interface address. Multicast addresses are shown on separate lines following the interface address with which they are associated. If -b is also present, show the number of bytes in and out. If -d is also present, show the number of dropped packets. If -t is also present, show the contents of watchdog timers."

    netstat -an | grep -i listen
    scubacuda · 2009-02-19 19:27:49 3

  • -2
    ip -f inet addr show eth0
    kev · 2012-04-02 15:12:40 3
  • ip address show | grep eth0 | sed '1d' | awk '{print $2}' does the same, but shows network-prefix.

    ip route show dev eth0 | awk '{print $7}'
    P17 · 2009-05-26 20:29:54 1

What Others Think

try awk '/ipv4.addresses/ {print $2}' to do the pattern match and field selection in one command.
snegtul · 158 weeks and 3 days ago
Ah, @snegtul beat me. However, the command doesn't work on my version of nmcli (Fedora 21) nmcli --version nmcli tool, version nmcli connection show eth0 ipv4.addresses: { ip =, gw = } so the simplest solution for me is sed: ... | sed '/ipv4.addresses/s/.* \(.*\),.*/\1/' Search for something delimited by space (before) and comma (after).
flatcap · 158 weeks and 3 days ago
I've just lernt that nmap --iflist is useful to show all ifaces, ip and routes. ..of course this doesn't work if we're looking for the ip to use it in a bash script.
nnsense · 157 weeks and 3 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands

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.


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: