6

The hardware universally unique identifier (UUID) can often be used by developers to associate information unique to a Mac. This identifier will usually persist through OS upgrades or reinstalls, as well as across multiple OSes in multi-boot installations. I would like to be able to retrieve the UUID via a command line in macOS in order to use with a script.

1 Answer 1

11

The ioreg command can be used for this task.

ioreg -d2 -c IOPlatformExpertDevice | awk -F\" '/IOPlatformUUID/{print $(NF-1)}'

Similarly, you can get the same information in a Property List (plist/xml) format by including the -a option which is useful for implementations that work with XML better. One command line example would be to use xmllint --xpath

ioreg -ad2 -c IOPlatformExpertDevice | 
  xmllint --xpath '//key[.="IOPlatformUUID"]/following-sibling::*[1]/text()' -

I often see the system_profiler command used for this task, however, I have found the ioreg method to be slightly faster if performance is a concern.

time system_profiler SPHardwareDataType | awk '/UUID/ { print $NF }'

real    0m0.295s
user    0m0.110s
sys     0m0.074s


time ioreg -d2 -c IOPlatformExpertDevice | awk -F\" '/IOPlatformUUID/{print $(NF-1)}'

real    0m0.029s
user    0m0.005s
sys     0m0.004s

You must log in to answer this question.

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