以下十多种方法,明白四种即可;
ifconfig eth0 |sed -n ‘2p‘ |sed‘s#^.*addr:##g‘|sed ‘s# B.*$##g‘
ifconfig|awk -F "[: ]+"‘NR==2{print $4}‘
ifconfig |awk NR==2|sed -r‘s#^.*r:(.*)B.*#\1#g‘
ifconfig |sed -rn ‘2s#^.*r:(.*)B.*#\1#gp‘
ifconfig eth0|grep "inet a"|sed -r ‘s#^.*r:(.*)B.*#\1#g‘
ifconfig eth0|sed -rn ‘/inet a/s#^.*r:(.*)B.*#\1#gp‘
ifconfig eth0|grep ‘inetaddr‘|cut -d ":" -f2|cut -d " " -f1
ifconfig eth0|grep ‘inet addr‘|awk -F ":" ‘{print $2}‘|awk ‘{print $1}‘
ifconfig eth0|grep ‘inet addr‘|awk -F ‘[ :]‘ ‘{print $13}‘
ifconfig eth0|sed -n ‘2p‘|awk-F ‘[ :]+‘ ‘{print $4}‘
ifconfig eth0 |awk -F‘[ :]+‘ ‘NR==2 {print $4}‘
ifconfig eth0 |sed -nr ‘2s#^.*dr:(.*) B.*$#\1#gp
ifconfig eth0|grep -Po ‘(?<=dr:)[0-9.]+‘
ifconfig eth0|sed -nr ‘2s#^.*addr:(.*) Bca.*$#\1#g‘p
ifconfig eth0|sed -n ‘2p‘|sed ‘s#^.*addr:\(.*\)Bc.*$#\1#g‘
hostname -l
原文地址:http://dalongge.blog.51cto.com/13121286/1957448