Get Mac Serial Number Command Line
To get your Mac’s serial number from the command line, open Terminal and run system_profiler SPHardwareDataType | grep "Serial Number" or simply ioreg -l | grep IOPlatformSerialNumber. The first command returns a labeled line with your serial; the second outputs a raw key-value pair. Both are built into macOS and require no extra software.
Why Use the Command Line?
Most people find the serial number in System Settings > General > About (or About This Mac on older versions). That’s fine for a single machine, but the command line becomes essential when you need to:
- Check the serial on a Mac that won’t boot past the login screen.
- Script an inventory of many Macs (e.g., in a lab or office).
- Verify a serial before buying a used Mac, when the seller only gives you SSH access.
- Automate a workflow that needs the serial as a variable.
Once you have the serial, you can look up warranty status, model details, or check if it’s been reported lost. The command line gives you the raw value quickly, without clicking through a GUI.
Two Main Commands
There are two reliable, built-in commands. They differ slightly in output format and speed.
1. system_profiler
Run this in Terminal:
system_profiler SPHardwareDataType | grep "Serial Number"
You’ll see something like:
Serial Number (system): C02XK2Z4JG5H
The grep filters the long output of system_profiler to just the line you need. If you want the serial alone (no label), use awk:
system_profiler SPHardwareDataType | awk '/Serial/ {print $4}'
This prints the fourth field (the value) from the line containing “Serial”.
2. ioreg
Run this instead:
ioreg -l | grep IOPlatformSerialNumber
Output:
"IOPlatformSerialNumber" = "C02XK2Z4JG5H"
To get just the serial, use awk with the equals sign as a delimiter:
ioreg -l | grep IOPlatformSerialNumber | awk -F'"' '{print $4}'
Both commands read the same hardware data, but ioreg tends to be faster because it doesn’t enumerate all hardware details. For scripting, ioreg is often preferred because its output is more predictable.
How to Read the Serial Number
Apple’s serial numbers are 11 or 12 characters (older Macs may have 11). The format isn’t publicly documented in detail, but the first three characters usually indicate the manufacturing location, the next two the year and week, and the rest are a unique identifier. For example, in C02XK2Z4JG5H, the first character C often points to a factory in China, and the following digits encode production date. However, Apple has changed the encoding over the years, so don’t rely on it for precise dates. Use the serial with Apple’s coverage check page or a third-party decoder for accurate model and warranty info.
Common Problems and Fixes
If the command returns nothing, try these checks:
- Typo in the command: Ensure you typed
system_profiler(notsystem_profiler) andSPHardwareDataTypeexactly. - No output from grep: The output might use a different label on your macOS version. Run
system_profiler SPHardwareDataTypealone and look for “Serial Number (system)” or just “Serial Number”. - Permission issues: Both commands work without sudo, but if you’re in a restricted environment (e.g., a managed Mac), you might need to run with
sudo(though it’s unusual). - Virtual machine: If you’re in a VM, the serial may be a generic string like “VMware-…” or blank.
If ioreg returns a long list, you might have missed the line. Use ioreg -l | grep -i serial to catch case variations.
Alternatives to the Command Line
If you can’t use Terminal, or you need the serial on a Mac that won’t boot, try these:
- About This Mac: Click the Apple menu > About This Mac. The serial is shown in the Overview tab.
- System Information app: Open
System Information.app(in /Applications/Utilities) and look under Hardware. - Physical device: On most MacBooks, the serial is printed on the bottom case. On iMacs and Mac minis, it’s often in the regulatory markings. For Mac Pro, check the back or the original box.
- Recovery mode: Boot into macOS Recovery (hold Command+R at startup) and open Terminal from the Utilities menu. Then use the same commands—they work there too.
Using the Serial in Scripts
Once you have the serial, you can store it in a variable for automation. For example, in a bash script:
SERIAL=$(ioreg -l | grep IOPlatformSerialNumber | awk -F'"' '{print $4}')
echo "This Mac's serial is $SERIAL"
You could then use that variable to query Apple’s coverage API (requires a network request) or to rename the computer based on the serial. This is common in enterprise environments where IT departments deploy many Macs at once.
Safety and Privacy
Your Mac’s serial number is not secret—it’s printed on the device and visible in system information. However, be cautious about sharing it publicly. A serial can be used to check warranty status, and in some cases, to create a fake repair history. Never post a serial number on a public forum unless you’re comfortable with that. Also, if you’re buying a used Mac, ask the seller for the serial and verify it with Apple before paying. This helps avoid stolen or counterfeit devices.
Frequently Asked Questions
Does the serial number change after a logic board replacement?
Yes. If Apple or a repair shop replaces the logic board, the serial number typically changes to match the new board. This is why a used Mac’s serial might not match the one printed on the bottom case. Always check the serial in software, not just the physical sticker.
Can I find the serial number if my Mac won’t boot?
Yes. Boot into macOS Recovery (hold Command+R at startup), open Terminal from the Utilities menu, and run ioreg -l | grep IOPlatformSerialNumber. You can also check the physical device (bottom case for laptops).
Why does system_profiler show “Serial Number (system)” instead of just “Serial Number”?
On newer macOS versions, the label includes “(system)” to distinguish it from other serial numbers (like the logic board serial). Your grep command should still match if you search for “Serial Number” without the parentheses.
Is there a way to get the serial number without typing a command?
Yes. Use the GUI: Apple menu > About This Mac. Or open System Information.app. The command line is just faster for scripting and remote access.
Can I use the serial number to find the model and year?
Yes. Apple’s coverage check page (checkcoverage.apple.com) will show the model name and purchase date if you enter the serial. Several third-party sites also decode the serial to show manufacturing details, but Apple’s official tool is the most reliable.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.