To get your Mac's serial number via the Terminal, type system_profiler SPHardwareDataType | grep Serial and press Enter. This command queries the system profile for hardware specifications and filters the results to show only the line containing your unique serial number.
Using the Terminal is an efficient way to retrieve hardware information, especially if you are managing multiple machines, writing a script, or if the graphical user interface (GUI) is unresponsive. This method accesses the same system data found in the "About This Mac" menu but delivers it in a plain-text format that is easy to copy and paste.
What You'll Need
- A Mac running macOS.
- An account with permissions to access the Terminal (standard user accounts can typically run this command without administrator privileges).
Step-by-Step
- Open the Terminal app: You can do this in two ways. Either press
Command (⌘) + Spacebarto open Spotlight, type "Terminal," and press Enter; or navigate to Finder > Applications > Utilities > Terminal. - Enter the command: Carefully type or copy and paste the following command into the window:
system_profiler SPHardwareDataType | grep Serial - Execute the command: Press the
Return(Enter) key on your keyboard. - Read the output: The Terminal will process the request and display a line of text that looks like:
Serial Number (system/Firmware Unique ID): C02XXXXX.... The alphanumeric string at the end is your Mac's serial number. - Copy the number: Highlight the serial number with your mouse and press
Command (⌘) + Cto copy it to your clipboard.
Common Mistakes
- Case Sensitivity: The command is case-sensitive. If you type
system_profiler sphardwaredatatype(all lowercase), the system will return an error because it does not recognize the data type. - Missing the Pipe Symbol: The vertical bar (
|), known as a "pipe," is crucial. It tells the Mac to take the output of the first command and send it to the second command (grep). If you omit it, the Terminal will list every single piece of hardware information, forcing you to scroll through dozens of lines to find the serial number. - Typing Errors in "grep": Ensure there is a space between
SPHardwareDataType, the pipe symbol, and the wordgrep. If the spacing is incorrect, the shell will not execute the command properly.
Tips
- Alternative Command: If you prefer a shorter command, you can use
ioreg -l | grep IOPlatformSerialNumber. This queries the I/O Registry directly. The output will be slightly different (formatted as a quoted string), but the serial number is the same. - Exporting to a File: If you need to save this serial number to a text file for documentation, you can redirect the output by adding
> serial.txtto the end of the command:system_profiler SPHardwareDataType | grep Serial > serial.txt
This creates a file named "serial.txt" in your current home directory containing the serial number. - Using Tab Completion: When typing
system_profiler, you can press the Tab key to help auto-complete commands, though this is more useful for file paths than for specific data type flags.
Troubleshooting
If the command does not return a serial number or returns an error, try these steps in order:
- Check for Typos: Re-read the command carefully. A single missing letter or an incorrect capital letter will cause the command to fail. The safest method is to copy and paste the command directly from this guide.
- Verify Terminal Permissions: While this command usually doesn't require root access, if you see a "Permission Denied" error, try running it with administrative privileges by adding
sudoto the front:sudo system_profiler SPHardwareDataType | grep Serial
You will be prompted for your Mac login password. Note that the cursor will not move while you type the password; this is a standard security feature. Press Enter when finished. - Restart the Terminal: If the Terminal seems frozen or is not responding to input, quit the app (
Command + Q) and relaunch it. - Check System Integrity: If
system_profilerreturns no data at all, there may be an issue with the system management controller (SMC) or the OS installation. In this case, try checking the serial number physically on the bottom of the laptop case or on the original packaging.
Frequently Asked Questions
Is this method safer than using the "About This Mac" menu?
Both methods are equally safe as they are simply reading existing system information. The Terminal method is simply faster for advanced users or those who cannot access the GUI.
Will this command work on M1, M2, or M3 Macs?
Yes, the system_profiler command is a core part of macOS and works across both Intel-based Macs and Apple Silicon (M-series) Macs.
Can I find the serial number of a Mac that won't boot into macOS?
No, the Terminal command requires the operating system to be running. If the Mac won't boot, you must look at the physical chassis of the device or check the original invoice/box.
Does this command reveal any private passwords or keys?
No. The SPHardwareDataType flag only requests hardware specifications like the model identifier, processor, and serial number. It does not access user files, passwords, or security keys.
Why does the output show "Firmware Unique ID"?
In some versions of macOS or on certain hardware configurations, the system labels the serial number as the Firmware Unique ID. These are the same identifier used for warranty and support purposes.