Quantcast
Viewing latest article 9
Browse Latest Browse All 9

Answer by steeldriver for Output only MAC address on Ubuntu

If you want a layer of abstraction away from the /sys/class/net interface you could use the nmcli command. For example, the GENERAL field of the dev[ice] object contains the interface type and hardware address (MAC):

$ nmcli -f GENERAL.DEVICE,GENERAL.TYPE,GENERAL.HWADDR dev showGENERAL.DEVICE:                         enp0s3GENERAL.TYPE:                           ethernetGENERAL.HWADDR:                         08:00:27:A7:C4:90GENERAL.DEVICE:                         enp0s9GENERAL.TYPE:                           ethernetGENERAL.HWADDR:                         08:00:27:8E:46:ABGENERAL.DEVICE:                         loGENERAL.TYPE:                           loopbackGENERAL.HWADDR:                         00:00:00:00:00:00

You can get the output in a more parsable form using the -g | --get-values option:

$ nmcli -g GENERAL.TYPE,GENERAL.HWADDR -e no dev showethernet08:00:27:A7:C4:90ethernet08:00:27:8E:46:ABloopback00:00:00:00:00:00

So for example in a script you could do

$ nmcli -g GENERAL.TYPE,GENERAL.HWADDR -e no dev show | awk -v RS= '$1 ~ "ethernet" {print $2}'08:00:27:A7:C4:9008:00:27:8E:46:AB

Viewing latest article 9
Browse Latest Browse All 9

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>