Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I use a lot of scripts that involve the Mac addresses of my network cards. Is there a file I can read or a command that I can use to JUST get the Mac address? I don't want any headers or anything, just 1 line of output that has the Mac address. I would like to set this as an environment variable on login. I use Arch Linux x64

share|improve this question
    
Whatever command you normally use to see the MAC address, pipe its output through awk (or perl, or ...) and pull out just the bit you want. –  alexis Jan 31 '13 at 19:29
    
Be aware that the MAC address is not a static unchangable value it used to be. Pretty much everywhere it is user configurable/changable. –  mdpc Feb 1 '13 at 3:32

2 Answers 2

up vote 3 down vote accepted
 VARIABLE="$(cat /sys/class/net/$IFACE/address)"

It's hard to do it simpler.

Well, actually:

 read -r MACADDRESS < /sys/class/net/$iFACE/address

is even simpler, and starts no additional process.

share|improve this answer
    
Awesome. Thanks so much! –  wolfo9999 Jan 31 '13 at 20:52

This works for me. Can probably be optimized a bit:

/sbin/ifconfig eth0 | grep -o 'HWaddr  *[0-9A-F:]*' | sed -s 's/HWaddr *//'

I don't think you can simplify it much from this. I did an strace on the ifconfig, and it seems you pull the MAC addr with an ioctl() on a socket, not from a /proc file.

share|improve this answer
1  
ifconfig is deprecated on Linux, in favor of ip, which is as easily parsable: ip link show dev eth0 | sed -nre 's@.*link\/ether (\S+).*@\1@p' –  BatchyX Jan 31 '13 at 19:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.