Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 18 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;}'
share|improve this answer
1  
+1 - Great answer bmike. –  boehj Feb 18 '12 at 23:02
add comment

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 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 at 19:24
1  
@MrPool when it does repeat what is in an earlier answer and does not improve on the previous one –  Mark Feb 13 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 at 19:28
1  
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 at 19:29
show 1 more comment

Your Answer

 
discard

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.