Get a Macs Serial Number from the Command Line
You can quickly retrieve any Macs serial number via the command line by using the system_profiler command and grep for the serial string. Getting the serial number from the command line like this can be helpful for troubleshooting, Single User Mode, remote management with SSH, or for many other reasons, though most users should opt to find the Macs serial number this way from the Apple menu or from System Profiler, the Terminal app method is valid for advanced users and for many other reasons.
How to Get the Serial Number of a Mac from Command Line in OS X
To try this yourself and get the serial number on any OS X machine, enter the appropriate command string below at the Terminal, depending on the version of OS X in use on the Mac. Be sure the command is on a single line, as usual with command line syntax.
On modern versions of OS X, like Yosemite and Mavericks, the following string will retrieve the Macs serial number:
system_profiler |grep "Serial Number (system)"
The results for this string will look something like the following:
$ system_profiler |grep "Serial Number (system)"
Serial Number (system): B041FAFDLLJA8
The serial number will always appear as an alphanumeric string alongside “Serial Number (system)”, if you simply grep for “serial” you’ll find a huge number of returns that are unrelated to the systems actual serial number, thus we don’t do that.
For querying the systems serial number in older versions of OS X, use the following system_profiler and grep string:
system_profiler |grep "r (system)"
The command results will look something like this:
$ system_profiler |grep "r (system)"
Serial Number (system): C24E1322XXXX
Again, the alphanumeric string after “Serial Number (system)” is the serial number.
Just as the new versions, if you just grep for “Serial Number” you’ll be presented with serial numbers to other hardware included in the Mac, which is why the “r (system)” qualifier is included.
If you’re having any issues with this, you may want to just go with the About This Mac approach instead, or have your Mac actually read the serial number to you which is possible from the System Profiler application.
Once you have a serial number, you can do things like check AppleCare warranty status and repair history.