Eject a Disk or Volume with hdiutil detach

Unmount and eject external drives and disk images from the command line.

macOSFileshdiutildiskLow risk
Run hdiutil detach followed by the mount point in quotes to safely eject the volume.

01Command

Command
$ 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

RiskLow risk
!Warning: Never unplug the drive without detaching first — pending writes can be lost.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

Last verified: 2026-09-18 · Category: Files & Folders

06Related solutions