Linux命令面试题积累(一)
面试题一:使用命令截取出ip地址
Linux环境
[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core)
利用ifconfig ens33 截取出ip地址
[root@localhost ~]# ifconfig ens33|awk 'NR==2{print $2}'
192.168.18.111
[root@localhost ~]# ifconfig ens33|sed -nr '2s#^.*inet (.*) netmask.*(.*)#\1#gp'
192.168.18.111
Linux环境
[root@localhost ~]# cat /etc/redhat-release CentOS release 6.5 (Final)
利用ifconifg eth0截取ip地址
[root@localhost ~]# ifconfig eth0|sed -nr '2s#^.*dr:(.*) B.*$#\1#gp'
192.168.18.11
[root@localhost ~]# ifconfig eth0|awk -F '[ :]+' 'NR==2{print $4}'
192.168.18.11

浙公网安备 33010602011771号