Get a Macs Serial Number from the Command Line

Apr 25, 2011 - 10 Comments

Terminal in Mac OS X You can quickly retrieve any Macs serial number via the command line by using the ioreg or 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 Mac OS X

To try this yourself and get the serial number on any Mac OS machine, enter the appropriate command string below at the Terminal, depending on the version of Mac OS X in use on the Mac. Be sure the command is on a single line, as usual with command line syntax.

How to Get Mac Serial Number by Command Line in Modern MacOS

On modern versions of MacOS like Mojave, High Sierra, and Sierra, or newer, the following command syntax will retrieve the serial number from the Mac:

ioreg -l | grep IOPlatformSerialNumber

The resulting output with serial number will look like the following:

"IOPlatformSerialNumber" = "C241BABDLLRP8"

How to Get Serial Number by Command Line in Prior Mac OS X

On prior versions of Mac OS X like El Capitan, 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.

Querying Mac Serial Number by Command Line in Older Mac OS X Releases

For querying the systems serial number in even older versions of Mac OS X, including Snow Leopard, Mt Lion, Lion, and before, 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.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS X, Tips & Tricks

10 Comments

» Comments RSS Feed

  1. stus says:

    faster:

    system_profiler SPHardwareDataType | grep “Serial”

  2. Squanto says:

    Using “About this Mac” under the Apple menu us much easier. Click the line between Mac OS X and above the Software Update button (by default you’ll see the version number, first click shows the build number and the second click will show your Mac’s serial number.)

    • Brandon says:

      The solution described by this post’s title, and indeed the whole purpose, is to get the computer’s serial number via the COMMAND LINE. How many paint chips did you eat as a child, Squanto?

    • Asdf says:

      I personally think that it’s a bit easier to use the command line when your computer won’t boot…

  3. B0bby says:

    Lol @ one machine in my office i have this serial number:
    SOMESRLNMBR

  4. motoko says:

    system_profiler SPHardwareDataType | awk ‘/Serial Number/ { print $4; }’

  5. David Dobie says:

    less to type and easier to remember

    system_profiler | less

    give the whole first page of system profile

  6. Dustin says:

    STUS… THANK YOU! Worked like a charm.

  7. Don Montalvo says:

    ioreg -l | grep IOPlatformSerialNumber

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site