Question: What command can I use to retrieve the system's serial number from the unix command line? As `uname` will output some information about the software and hardware, I would like to retrieve the serial number from a command to use in a script.

Answer: 
This also works…

```
ioreg -l | grep IOPlatformSerialNumber

```
C++ example from <https://developer.apple.com/library/archive/technotes/tn1103/_index.html>:

```
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>

std::string 

getSerialNumber()

{

   CFStringRef serial;
    char buffer[32] = {0};
    std::string seriaNumber;

io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault,
                                                          IOServiceMatching("IOPlatformExpertDevice"));
if (platformExpert)
{
    CFTypeRef serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert,
                                                                       CFSTR(kIOPlatformSerialNumberKey),
                                                                       kCFAllocatorDefault, 0);
    if (serialNumberAsCFString) {
        serial = (CFStringRef)serialNumberAsCFString;
    }
    if (CFStringGetCString(serial, buffer, 32, kCFStringEncodingUTF8)) {
        seriaNumber = buffer;
    }

    IOObjectRelease(platformExpert);
}
return seriaNumber;
}

```