Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 5 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! – Wolfizen 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
    
Have you figured out a way to do this without regular expressions? – Ben Aug 11 '14 at 18:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .