How to get only IP in linux

One, get the command

ifconfig
ifconfig |head -2 |grep inet |awk '{print $2}'
ifconfig |head -2 |tail -1 |tr -s ' ' |cut -d' ' -f3
ifconfig |grep -Eo '([0-9]{1,3}.){3}[0-9]{1,3}' |head -1

Two, write scripts are permanently retained

vim ip.sh


#!/bin/bash
######
ifconfig |head -2 |grep inet |awk '{print $2}'
ifconfig |head -2 |tail -1 |tr -s ' ' |cut -d' ' -f3
ifconfig |grep -Eo '([0-9]{1,3}.){3}[0-9]{1,3}' |head -1

chmod u+x ip.sh
./ip.sh

 

Guess you like

Origin blog.csdn.net/l_liangkk/article/details/105169891