diskutil eject: How to Eject Drives From Mac Terminal

Eject any Mac drive from Terminal with diskutil — including force-unmounting a volume that won't eject and using lsof to find what's holding it.

Finder tells you the drive is in use. It doesn’t tell you what’s using it or what to do about it. Terminal does both.

Quick answer: Run diskutil eject /Volumes/YourDriveName to eject a drive from Terminal. If it fails, use sudo lsof /Volumes/YourDriveName to see what’s blocking ejection, kill <PID> to stop the offending process, then eject again. As a last resort, diskutil unmountDisk force /dev/diskN forces the drive off, but only do this when nothing is actively writing.

If you’re comfortable with the command line, Terminal is the most powerful way to handle stubborn drive ejections on macOS. And if you’re not comfortable with it yet, these commands are a good place to start.

Basic ejection with diskutil eject

The most direct way to eject an external drive from Mac Terminal:

diskutil eject /Volumes/YourDriveName

Replace YourDriveName with your drive’s actual name — exactly as it appears in Finder. If the name has spaces, wrap it in quotes:

diskutil eject "/Volumes/My Drive"

This does the same thing as clicking the eject button in Finder. If it works, the drive unmounts cleanly and you’re done. If it fails, you get a more informative error message than Finder ever provides.

You can also unmount without ejecting (the drive stays visible in Disk Utility but isn’t mounted):

diskutil unmount /Volumes/YourDriveName

The difference matters for multi-partition drives. unmount removes one volume. eject removes the physical device and all its volumes at once.

Finding your drive’s identifier with diskutil list

Before using more advanced commands, you need your drive’s identifier. List all connected disks:

diskutil list

The output shows every disk and its partitions. Your external drive will be something like disk4 or disk5. Internal drives are usually disk0 and disk1.

For a more readable overview of just external drives:

diskutil list external

Once you know the disk identifier, you can also eject using the /dev/ path instead of the volume name:

diskutil eject /dev/disk4

This is useful when the volume name contains unusual characters or when the volume isn’t mounted but the disk is still attached.

How to eject all external drives at once

If you need to eject every external drive in one command, there are two approaches.

Using diskutil to find and eject all external disks:

diskutil list external | grep -o 'disk[0-9]*$' | while read disk; do diskutil eject "/dev/$disk"; done

Or using AppleScript from Terminal, which mirrors what Finder does:

osascript -e 'tell application "Finder" to eject (every disk whose ejectable is true)'

The AppleScript approach only ejects disks Finder considers ejectable — it skips your startup disk and network volumes, which is usually what you want.

Force unmounting when diskutil eject fails

If a normal eject fails with an error like “couldn’t unmount disk,” force it:

diskutil unmount force /Volumes/YourDriveName

Or unmount all volumes on a specific disk at once:

diskutil unmountDisk force /dev/disk4

Force unmount tells macOS to release the volume regardless of what’s using it. It’s more controlled than physically unplugging the drive — the system still flushes caches and notifies processes — but it doesn’t wait for processes to close files cleanly.

Use force unmount when you know nothing important is being written. It’s the command-line equivalent of force-ejecting from Disk Utility. See our guide on when force eject is safe vs. risky before using this on a drive that was actively in use.

Finding what’s blocking ejection with lsof

This is the command that makes Terminal invaluable for ejection problems:

lsof /Volumes/YourDriveName

lsof stands for “list open files.” It shows every process that has a file open on that volume — the process name, process ID (PID), the user running it, and which file is open. (For a focused walkthrough of lsof flags and patterns, see our lsof command guide for Mac users.)

For complete results (including system processes), run it with sudo:

sudo lsof /Volumes/YourDriveName

Without sudo, you only see processes owned by your user account. System processes like Spotlight’s mds or Time Machine’s backupd won’t appear. With sudo, you see everything that’s actually holding the drive open.

Reading the lsof output

The output looks something like this:

COMMAND   PID   USER   FD   TYPE   DEVICE   SIZE/OFF   NODE   NAME
mds       123   root   12r  REG    1,8      4096       789    /Volumes/MyDrive/.Spotlight-V100/...
Finder    456   aaron  15r  DIR    1,8      1024       2      /Volumes/MyDrive
Dropbox   789   aaron  8u   REG    1,8      8192       345    /Volumes/MyDrive/Projects/.dropbox

The columns that matter most:

  • COMMAND: The process name — this tells you what’s blocking ejection.
  • PID: The process ID — you’ll use this to kill the process if needed.
  • FD: File descriptor and access mode. r means read, w means write, u means read/write. If you see w or u, something is actively writing to the drive, and force-ejecting is risky.
  • NAME: The specific file being accessed — this often reveals exactly why the process is there.

Common culprits: mds (Spotlight indexing), backupd (Time Machine), Dropbox, Google Drive, Finder itself. See our deep-dives on Spotlight blocking ejection and iCloud/Dropbox preventing ejection for targeted fixes.

Killing blocking processes

Once you know the PID of a blocking process, terminate it gracefully:

kill 789

This sends a graceful termination signal. The process gets a chance to close files and clean up. Give it a few seconds to exit, then try ejecting again.

If it doesn’t respond to a graceful kill:

kill -9 789

This forces immediate termination. The process doesn’t get to clean up. Use this as a last resort — especially for system processes.

To kill all processes using a specific volume in one command:

sudo lsof -t /Volumes/YourDriveName | xargs kill

The -t flag makes lsof output only PIDs, and xargs feeds them to kill. Be careful: this kills every process using the drive, including ones that might be in the middle of important work.

Complete troubleshooting workflow

Here’s the full sequence for a drive that won’t eject:

# Step 1: Try normal eject
diskutil eject /Volumes/YourDriveName

# Step 2: If that fails, see what's blocking
sudo lsof /Volumes/YourDriveName

# Step 3: Kill the offending process (replace PID with actual number)
kill 12345

# Step 4: Try ejecting again
diskutil eject /Volumes/YourDriveName

# Step 5: If still stuck, force unmount
diskutil unmountDisk force /dev/disk4

Most problems are resolved at Step 3. Identify the blocker, kill it, eject cleanly.

Useful diagnostic variations

Check if Spotlight specifically is holding your drive:

lsof /Volumes/YourDriveName | grep mds

List only the unique process names blocking ejection (no duplicate lines):

lsof /Volumes/YourDriveName | awk '{print $1}' | sort -u

Watch real-time disk I/O to see if something is actively writing:

sudo fs_usage -f diskio | grep YourDriveName

This runs continuously and shows every disk operation as it happens. Press Control-C to stop. Use this when lsof shows a process but you’re not sure if it’s actively writing or just holding a stale handle.

When Terminal is more work than it’s worth

These commands are powerful, and once you’ve used them a few times, they become second nature. But there’s a real cost to context-switching from your work to a Terminal window — running diagnostic commands, parsing technical output, deciding which PID is safe to kill.

Ejecta does everything above automatically. It monitors your drives, identifies every blocking process, and gives you a one-click button to quit each one. The same information you’d get from sudo lsof, presented visually right in your menu bar — no commands to remember, no output to parse.

For $9.99, you get a tool that replaces this entire multi-step Terminal workflow with a single click. If you’re fighting this problem more than once a month, it pays for itself in saved frustration within the first week. Try Ejecta free for 7 days — no Terminal required.

If you'd rather not use Terminal every time, Ejecta shows you exactly which process is blocking your drive — and lets you quit it with one click, right from your menu bar.

Buy Now — $9.99