Skip to content

Instantly share code, notes, and snippets.

@carlessanagustin
Created March 14, 2016 09:42
Show Gist options
  • Save carlessanagustin/272008d3824c47505ebf to your computer and use it in GitHub Desktop.
Save carlessanagustin/272008d3824c47505ebf to your computer and use it in GitHub Desktop.
Get only the IP address
# method 1
$ echo $(ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
# method 2
$ echo $(ip -o -4 addr list eth0 | perl -n -e 'if (m{inet\s([\d\.]+)\/\d+\s}xms) { print $1 }')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment