What diskutil
is and when to use it
diskutil
is Apple’s command-line Swiss-army knife for managing disks, partitions,
APFS containers, Core Storage groups, and external media on macOS.
It exposes far more verbs (“sub-commands”) than the Disk Utility GUI, ranging from simple listings to
live container resizing.
$ diskutil [quiet] verb [options]
Listing devices, volumes, and containers
Verb | Description |
---|---|
list | Show all disks, partitions, APFS objects. |
info device | Detailed properties for a single disk/partition. |
activity | Live event stream of mounts, ejects, renames. |
apfs list | Tree view of APFS containers & volumes. |
cs list | Legacy Core Storage logical volume groups. |
# All media
$ diskutil list
# Inspect the boot volume
$ diskutil info /
# APFS hierarchy only
$ diskutil apfs list
Safely wiping or re-formatting disks & volumes
$ diskutil eraseDisk APFS "Macintosh HD" GPT /dev/disk3
Specify Scheme
(MBR, GPT or APM),
Filesystem
(JHFS+, APFS, ExFAT…), a volume label, and the physical device node.
$ diskutil eraseVolume JHFS+ Data /Volumes/USB
On rotational disks use secureErase (N-pass overwrite). On SSD/APFS the command zeros the metadata; rely on FileVault for cryptographic erasure instead.
Creating, resizing, deleting partitions live
$ diskutil addPartition disk0s2 MS-DOS BOOT 20G
$ diskutil partitionDisk /dev/disk2 GPT \
APFS System 250G \
MS-DOS SHARE 100G \
0B
$ diskutil apfs resizeContainer disk1s2 400G
Modern container & snapshot operations
$ diskutil apfs create /dev/disk3 "Data"
$ diskutil apfs addVolume disk4 APFS Projects \
-reserve 50g -quota 120g
# List snapshots
$ diskutil apfs listSnapshots /
# Create snapshot via filesystem utility first; then:
$ tmutil snapshot # or fs_snapshot_create()
First Aid without the GUI
$ diskutil verifyVolume /Volumes/Backup
$ diskutil repairVolume /dev/disk4s1
$ diskutil repairDisk /dev/disk3
Attach, detach, and force operations
$ diskutil mount /dev/disk3s1
$ diskutil unmount /Volumes/USB
$ diskutil eject disk3
$ diskutil unmountDisk force /dev/disk3
Automating diskutil
in Bash or Python
Add the quiet
flag to suppress chatty progress lines—ideal for LaunchAgents.
$ diskutil info -plist disk0 | plutil -convert json - - o -
Use diskutil activity in a background process to parse attach/detach events and trigger follow-up actions.
Avoiding catastrophic data loss
/dev/diskN
identifier with list before erasing.Official manuals & community guides