三剑客取ip地址

image.png
image.png
[root@m01 ~]# hostname -I|awk '{print $1}'
10.0.0.61
[root@m01 ~]# hostname -I|cut -d " " -f1 
10.0.0.61
[root@m01 ~]# awk -F= '/IPADDR/{print $2}'  /etc/sysconfig/network-scripts/ifcfg-eth0  
10.0.0.61
[root@m01 ~]# sed -n '/IPADDR/s#^.*=##gp' /etc/sysconfig/network-scripts/ifcfg-eth0
10.0.0.61
[root@m01 ~]# ip a  s eth0 |awk -F'[ /]+' 'NR==3{print $3}'
10.0.0.61
[root@m01 ~]# ip a  s eth0 |awk -F'inet |/24' 'NR==3{print $2}'
10.0.0.61
[root@m01 ~]# ip a  s eth0 |awk -F'[^0-9.]+' 'NR==3{print $2}'
10.0.0.61
[root@m01 ~]# ip a s eth0 |sed -nr '3s#^.*et |/.*$##gp'
10.0.0.61
[root@m01 ~]# ip a s eth0 |sed -nr '3s#^.*et (.*)/.*$#\1#gp'
10.0.0.61
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容