One Line IP Address Bash Command

ifconfig eth0 | sed -n '/^[A-Za-z0-9]/ {N;/dr:/{;s/.*dr://;s/ .*//;p;}}'

So you want to display just your IP address and not all the other stuff that comes with using the ifconfig command. Then use the above command.

It’s useful if you need your IP address in a script but you don’t want to set a static address for your machine, it outputs just the IP address on a single line as shown below:

4 comments to One Line IP Address Bash Command

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>