Eject a Disk or Volume with hdiutil detach
Unmount and eject external drives and disk images from the command line.
01Command
$ hdiutil detach "/Volumes/MyUSB"02What it does
Quote the path because volume names often contain spaces. If detach fails with "resource busy", something still has a file open — lsof +D /Volumes/MyUSB shows which process. hdiutil eject works the same way; detach is its exact synonym. This is the scripted equivalent of the Finder eject button and flushes pending writes first.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- hdiutil – Create and manipulate disk imagesEvidence: hdiutil detach unmounts and ejects a volume identified by its mount point or device node.
Last verified: 2026-09-18 · Category: Files & Folders
06Related solutions
List the biggest files in your home folder that are eating disk space.
Make Finder display .pdf, .docx, .png and every other extension at all times.
Build an AES-256 encrypted .dmg vault from the Terminal — no Disk Utility clicking required.