How to Erase a Mac's Hard Drive Using Terminal (2025 Guide)
Erasing a Mac's hard drive using Terminal can be a faster and more flexible option than using Disk Utility. This guide explains the step-by-step process to securely erase your Mac's hard drive, including optional secure erase methods for sensitive data.
Table of Contents
- Introduction
 - Step 1: Identify the Disk
 - Step 2: Unmount the Disk
 - Step 3: Erase the Disk
 - Step 4: Secure Erase (Optional)
 - Important Considerations
 - Final Notes
 
Introduction
Using Terminal to erase a hard drive gives you more control compared to using graphical tools like Disk Utility. It's especially useful for troubleshooting, securely erasing sensitive data, or preparing a disk for a new installation.
Step 1: Identify the Disk
First, open the Terminal app and list all available drives by typing:
diskutil list
Find the disk you want to erase (example: /dev/disk2).
Step 2: Unmount the Disk
Before erasing, unmount the disk:
diskutil unmountDisk /dev/disk#
Replace # with the correct disk number. If it refuses, force unmount:
diskutil unmountDisk force /dev/disk#
Step 3: Erase the Disk
Format the drive using your desired file system:
- APFS: Best for modern macOS versions.
 - JHFS+: For compatibility with older Macs.
 - ExFAT: Cross-platform between Mac and Windows.
 - FAT32: Older format, widely compatible but limited.
 
Command to erase and reformat the disk:
diskutil eraseDisk FORMAT DRIVE_NAME /dev/disk#
Example:
diskutil eraseDisk ExFAT MyDrive /dev/disk2
Step 4: Secure Erase (Optional)
If you need to securely erase data (not recommended for SSDs due to wear), use:
diskutil secureErase LEVEL /dev/disk#
Where LEVEL can be:
- 0: Single-pass zero-fill
 - 1: Single-pass random data
 - 2: US DoD 7-pass erase
 - 3: Gutmann 35-pass erase
 - 4: 3-pass random and zero-fill
 
Example:
diskutil secureErase 2 /dev/disk2
Important Considerations
- SSDs and flash drives: Avoid secureErase to prevent excessive wear.
 - Data recovery: Secure erase minimizes but does not guarantee complete data destruction.
 - Encryption: Consider encrypting your drive before wiping for extra security.
 - Drive errors: Persistent problems during erase may indicate failing hardware.
 
Final Notes
Terminal commands offer precision and flexibility when erasing a Mac hard drive. Whether you're preparing a drive for resale, troubleshooting, or safeguarding sensitive data, following these steps ensures a thorough and secure wipe.
For more detailed examples and advanced methods, you can visit the original guide:



