1、查看网卡设备
# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.26.211.25 netmask 255.255.240.0 broadcast 172.26.223.255
ether 00:16:3e:05:e7:df txqueuelen 1000 (Ethernet)
RX packets 3304474 bytes 1156152337 (1.0 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2714183 bytes 1173508935 (1.0 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2、先行过滤再列截取
# ifconfig eth0 | grep 'inet'
inet 172.26.211.25 netmask 255.255.240.0 broadcast 172.26.223.255
3、-s 删除所有重复出现字符序列,只保留第一个
# ifconfig eth0 | grep 'inet' |tr -s ' '
4、执行以上命令后,如果要取
inet 则为ifconfig eth0 | grep 'inet' |tr -s ' ' | cut -d' ' -f2
如果要取 172.26.211.25 则为 ifconfig eth0 | grep 'inet' |tr -s ' ' | cut -d' ' -f3
5、过滤ip
# ifconfig eth0 | grep 'inet' |tr -s ' ' | cut -d' ' -f3
172.26.211.25
6、过滤子网掩码
# ifconfig eth0 | grep 'inet' |tr -s ' ' | cut -d' ' -f5
7、过滤子网掩码、IP、网关
# ifconfig eth0 |grep 'inet' |tr -d 'a-zA-Z:' |tr ' ' '\n' |grep -v '^$'
8、过滤inet的行,去掉大小字符和冒号,对空格替换成回车符号
# ifconfig eth0 |grep 'inet' |tr -d 'a-zA-Z:' |tr ' ' '\n'
9、过滤inet的行,去掉大小字符和冒号
# ifconfig eth0 |grep 'inet' |tr -d 'a-zA-Z:'
10、过滤inet的行
# ifconfig eth0 |grep 'inet'
11、过滤MC地址【过滤ether行,压缩空格,以空格为分隔符,取第3列】
# ifconfig eth0 |grep 'ether'|tr -s ' ' |cut -d' ' -f3
00:16:3e:05:e7:df
12、过滤ether行,压缩空格
# ifconfig eth0 |grep 'ether'|tr -s ' '
声明:以上纯属博主学习历程笔记,依靠参考及其理解实战编写而成,后期会持续更新!
参考: