Ask Different is a question and answer site for power users of Apple hardware and software. 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

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.

share|improve this question
up vote 30 down vote accepted

The system_profiler command is perhaps the best tool for the job (assuming you are on 10.3 or newer), but you can also use ioreg for the task.

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}'


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 and remove the " you can have your answer in 0.005s or so:

ioreg -c IOPlatformExpertDevice -d 2 | awk -F\" '/IOPlatformSerialNumber/{print $(NF-1)}'
share|improve this answer
+1 - Great answer bmike. – boehj Feb 18 '12 at 23:02
The ioreg one is near instant on my MBPR. system_profiler although faster on this mac than my older ones is much slower. – markhunte Feb 17 '15 at 16:52

This also works…

ioreg -l | grep IOPlatformSerialNumber
share|improve this answer
It's certainly easier to type than the awk version to strip out the the 600 lines of ioreg output we don't want to see. (also - don't mind the down voters - some people really don't like short answers or forget that not everyone knows how grep and awk work.) – bmike Feb 13 '14 at 19:16
Ok, thanks bmike, it seems simpler to me, but didn't expect down votes for a correct answer. Good to know. – MrPool Feb 13 '14 at 19:24
@MrPool when it does repeat what is in an earlier answer and does not improve on the previous one – Mark Feb 13 '14 at 19:28
They are not wrong votes per se. Even down votes are good as they indicate someone cares enough to take action. Also, I try to comment or post to chat when I see votes that don't strike me as totally fair in sum. The good news is up votes are +10 and down votes only -2 so if you post something controversial (like this zero balance with +2 and -2 is still +16 rep.) welcome to the internet ;-) – bmike Feb 13 '14 at 19:28
And mark is correct, if all a user does is post exclusively late, short, minor changes without explaining (if I guessed your point - typing grep is both more clear, shorter, and good enough for many) I might ping that user and ask they knock it off. Most high reputation users would comment on my answer, but we can't expect a new user with 1 rep to do that, now can we :-) – bmike Feb 13 '14 at 19:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.