diskutil is the macOS command-line utility for managing disks and volumes. It lists storage devices, creates and resizes partitions, formats and erases volumes, mounts and ejects media, verifies and repairs file systems, and manages APFS containers. It is the Terminal counterpart of the graphical Disk Utility app, and both rely on the same system framework.
In Terminal & scripting on macOS, diskutil matters because it works where the graphical app cannot: in scripts, remote SSH sessions and macOS Recovery, and with options the app does not expose. Many of its verbs are destructive and act immediately, so precise disk identifiers are essential.
How diskutil addresses disks and volumes
diskutil works with device identifiers such as disk0, disk3 or disk3s1, where the number after disk names a physical or synthesized disk and the s suffix names a slice or volume. The command diskutil list prints every disk with its partition map, sizes and identifiers, and it should be the first command in any disk session.
On modern Macs, an APFS container appears as a synthesized disk. The physical internal SSD might be disk0, while its APFS container appears as disk3 with volumes disk3s1, disk3s5 and others. Identifiers are not stable across restarts or reconnections, so scripts should resolve them at run time or use volume UUIDs.
The table below explains the main kinds of identifiers diskutil accepts.
| Identifier | Example | Stability |
|---|---|---|
| Device node | disk4s2 | Changes between sessions |
| Mount point | /Volumes/Backup | Changes if the volume is renamed |
| Volume UUID | Long hexadecimal string | Stable for the life of the volume |
| Disk path | /dev/disk4 | Same as the device node |
Core diskutil verbs
diskutil is organized around verbs that follow the command name, and APFS-specific operations sit under the apfs verb. Running diskutil with no arguments prints the full list, and adding a verb without parameters shows its usage.
| Verb | What it does | Destructive |
|---|---|---|
| list | Shows all disks, partitions and identifiers | No |
| info | Prints detailed properties of one disk or volume | No |
| mount / unmount | Attaches or detaches a volume | No |
| eject | Unmounts all volumes and releases removable media | No |
| verifyVolume | Checks file system consistency | No |
| repairVolume | Repairs a damaged file system | Low risk |
| eraseDisk | Erases a whole disk with a new partition map | Yes |
| eraseVolume | Reformats a single volume | Yes |
| partitionDisk | Creates a complete partition layout | Yes |
| apfs addVolume | Adds a volume to an APFS container | No |
A typical erase looks like diskutil eraseDisk APFS Archive GPT disk4: the file system format, the new volume name, the partition scheme and the target. The command diskutil listFilesystems shows which format names the current system accepts.
File systems and partition schemes in diskutil
diskutil can create several file system formats, and the right choice depends on which devices must read the disk. APFS is the default for Mac storage, while ExFAT is the common choice for drives shared with Windows.
| Format name | Best for | Limitation |
|---|---|---|
| APFS | Internal SSDs, modern external drives | Not readable by Windows without extra software |
| JHFS+ | Older Macs and some Time Machine disks | No snapshots or space sharing |
| ExFAT | Drives shared between macOS and Windows | No journaling, higher corruption risk |
| MS-DOS FAT32 | Small media, cameras, legacy devices | Maximum file size of 4 GB |
The partition scheme sets how the disk is divided. GPT, the GUID Partition Table, is correct for almost every modern use, MBR remains for some older devices, and APM is a legacy Apple scheme for PowerPC-era Macs. A disk must be erased with GPT before macOS can install or boot from it.
diskutil compared with related tools
Several macOS tools touch storage, and choosing the correct one avoids unnecessary risk. diskutil manages disks and volumes, whereas hdiutil works with disk image files such as .dmg and .sparsebundle, and tmutil controls Time Machine.
Disk Utility offers the same core functions with a safer interface, but it hides some options, such as non-default partition layouts and certain APFS commands. The low-level tools fsck_apfs and gpt give even finer control, yet they bypass the protections diskutil adds, so experienced administrators reserve them for recovery situations.
For automation, diskutil offers a machine-readable output mode. Adding -plist to verbs such as list and info returns a property list that scripts can parse with plutil or PlistBuddy, which is far more reliable than scraping the human-readable columns. Most modifying verbs also require administrator privileges through sudo when they touch internal disks or system volumes.
Safety rules and common mistakes
diskutil does not ask for confirmation before most destructive operations, so the main danger is targeting the wrong disk. A careful workflow always runs diskutil list immediately before an erase and confirms the size and name of the target.
| Mistake | Cause | Prevention |
|---|---|---|
| Erasing the wrong disk | Reused an old identifier | Run diskutil list right before erasing |
| Unmount fails with resource busy | An app still holds open files | Quit the app or use lsof to find it |
| Repair reports errors on the boot volume | The volume is in use | Repair from macOS Recovery |
| Windows cannot read the drive | Formatted as APFS | Use ExFAT for cross-platform drives |
| Script breaks after a restart | Identifiers changed | Resolve by volume UUID |
On Apple silicon and T2 Macs, internal storage is always encrypted in hardware, so an erase that removes the encryption keys makes data practically unrecoverable. That is useful for secure disposal, and it also means a mistaken erase cannot be undone with recovery software.
Understanding it simply
Every Mac has a program called Disk Utility for preparing and fixing drives. diskutil is the same toolbox operated by typing commands instead of clicking buttons.
Typing commands is faster when the same job must be repeated or done on a remote computer. It is also less forgiving: diskutil does exactly what it is told, with no second question. That is why careful users always check which drive they are pointing at before erasing anything.
Applied in practice
An IT administrator at a design studio prepares twenty external SSDs for project archiving. Clicking through Disk Utility twenty times would take a long time and invite mistakes, so she writes a short zsh script around diskutil.
For each drive, the script runs diskutil list external physical, checks that the reported size is about 2 TB, and only then runs diskutil eraseDisk APFS Archive GPT with that identifier. A drive with an unexpected size is skipped and logged rather than erased.
The whole batch finishes in under fifteen minutes. One drive is flagged because a colleague had connected a personal disk of a different size, and the size check prevented data loss. Each archive drive is formatted identically, which simplifies later backup verification.