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: 
The [system\_profiler](https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man8/system_profiler.8.html) command provides a direct answer that’s easily human readable (assuming you are on 10.3 or newer), but you can also use [ioreg](https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man8/ioreg.8.html) for the task as it generally completes faster.

`system_profiler SPHardwareDataType` is the data type that contains the core hardware information, and you can use grep or awk to pare things down further as needed:

```
system_profiler SPHardwareDataType | awk '/Serial/ {print $4}'

```

or

```
ioreg -l | awk '/IOPlatformSerialNumber/ { print $4;}'

```

Both of those commands take between 0.5 and 0.2 seconds to run on modern SSD Macs, so if you want to [optimize the command](https://gist.github.com/chilcote/9b5f46ac6fdb801633e4) and [remove the "](https://twitter.com/pmbuko/status/563051228444504064) you can have your answer in 0.005s or so:

```
ioreg -c IOPlatformExpertDevice -d 2 | awk -F\" '/IOPlatformSerialNumber/{print $(NF-1)}'

```
To make it easier to remember, use a case insensitive search: 

```
ioreg -l | grep -i serialnumber | grep -i platform

```