How to Eject an External Drive From Terminal on Mac

Terminal gives you more control over drive ejection than Finder ever will. Here's every command you need to diagnose and resolve ejection problems.

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.

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

The most straightforward Terminal eject command:

diskutil eject /Volumes/YourDriveName

This does the same thing as clicking the eject button in Finder. If it works, the drive unmounts and you’re done. If it fails, you get a more informative error message than Finder 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.

Finding your drive’s identifier

Before using more advanced commands, you need to know your drive’s disk 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:

diskutil list external

This filters to just external drives, making it easier to find yours.

Force unmounting

If a normal unmount fails, force it:

diskutil unmount force /Volumes/YourDriveName

Or unmount all volumes on a 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 because 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.

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 the specified volume. The output includes the process name, process ID (PID), the user running it, and which file is open.

If the output is long, narrow it down:

lsof /Volumes/YourDriveName | head -20

This shows the first 20 entries, which is usually enough to identify the problem.

Important: for complete results, run it with sudo:

sudo lsof /Volumes/YourDriveName

Without sudo, you only see processes owned by your user account. System processes that might be blocking your drive won’t appear. With sudo, you see everything.

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.
  • 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 writing to the drive, and force-ejecting is riskier.
  • NAME: The specific file being accessed. This often reveals why the process is there.

Killing blocking processes

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

kill 789

This sends a graceful termination signal. The process has a chance to close files and clean up. Give it a few seconds to exit.

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 with this because it will kill every process using the drive, including ones that might be doing important work.

Combining it all into a workflow

Here’s a complete troubleshooting 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)
kill 12345

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

# Step 5: If still stuck, force unmount
diskutil unmount force /Volumes/YourDriveName

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

Useful variations

Check if a specific process is using your drive:

lsof /Volumes/YourDriveName | grep Spotlight

List only the process names (no duplicates):

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

See how much I/O each process is doing on the drive:

sudo fs_usage -f diskio | grep YourDriveName

This runs continuously and shows real-time disk operations. Press Control-C to stop. Use this to tell whether a process is actively reading/writing or just holding a stale handle.

When Terminal is too much work

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

Ejecta does everything in this article automatically. It monitors your drives, identifies blocking processes, and gives you a button to quit each one. The same information you’d get from lsof, presented visually with one-click resolution.

Terminal gives you complete control over drive ejection. Ejecta gives you that same control without having to think about it. For $7.99, you get a tool that replaces a multi-step command-line workflow with a single click from your menu bar.