通过ifconfig命令显示ip地址

1.首先找到IP地址位置

ifconfig

image

2.利用grep命令过滤inet信息

ifconfig | grep inet

image

3.利用head命令取所需IP的行

ifconfig | grep inet | head n1

image

4.利用awk命令分割取值,以空格为分隔符号输出需要的行

ifconfig | grep inet | head -n1 | awk -F' ' '{print $1" "$2}'

image

posted @ 2025-08-31 17:10  ITZhong  阅读(37)  评论(0)    收藏  举报