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.


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

To list all UUIDs I use the following code in Terminal:

for i in $(diskutil list | grep HFS | tr -s ' ' '\t' | cut -f 7); do diskutil info $i | grep UID | tr -s ' ' '\t' | cut -f 4; done
  • This an attempt to list the UUID of disks and volumes, which are different from the hardware UUID, and will often change when a volume is deleted and recreated. – n8felton Nov 8 '18 at 18:48
  • oops - my mistake - may be useful to somebody – Neville Hillyer Nov 9 '18 at 9:56

You must log in to answer this question.

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