Best way to extract MAC address from ifconfig's output?

前端 未结 19 1814
面向向阳花
面向向阳花 2020-12-12 15:31

What is the best way to extract the MAC address from ifconfig\'s output?

Sample output:

bash-3.00# ifconfig eth0        
eth0      Link          


        
19条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 16:10

    How about this one:

    ifconfig eth0 | grep -Eo ..\(\:..\){5}
    

    or more specifically

    ifconfig eth0 | grep -Eo [:0-9A-F:]{2}\(\:[:0-9A-F:]{2}\){5}
    

    and also a simple one

    ifconfig eth0 | head -n1 | tr -s ' ' | cut -d' ' -f5`
    

提交回复
热议问题