linux中仅获取IP的方法

一、 获取命令

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

二、 写入脚本永久保留

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

猜你喜欢

转载自blog.csdn.net/l_liangkk/article/details/105169891