Image for article titled Use This Terminal Command to Force Eject a Stubborn Disk From Your Mac

Photo: The Image Party (Shutterstock)

We’ve all been there: You have an external hard drive or USB thumb stick plugged into your Mac, and you’re ready to part ways. You drag it to the the Trash, or right-click to eject it, only to be greeted by the infamous, “The disk wasn’t ejected because one or more programs may be using it.” You look around your Mac: No app is open, no program is running. Whatever is causing the ejection delays certainly isn’t your fault. In the wise words of Peter Parker, “I missed the part where that’s my problem.”

Unfortunately, macOS has made it your problem. There could be multiple reasons why your computer won’t let go of your disk (we’ve run through them before), but often, the main issue is this: macOS is running a process accessing a file on the disk you can’t see. That’s why, even though everything is shut down and closed as far as you can see, your Mac insists the disk is in use. We all have trouble letting go sometimes.

That said, your Mac doesn’t always leave you hanging out to dry: Occasionally, you’ll see the option to Force Eject the disk, but even that solution comes with a caveat: How do you really know your Mac isn’t currently writing something to the disk? If you force eject it, either with software or by unplugging the disk from your Mac, you could damage its data.

Luckily, there’s a simple solution, so long as you’re OK using Terminal. In a Reddit thread musing on this subject, one user suggested the following command to quickly end any unknown processes running between macOS and your hard drive:

sudo lsof /Volumes/{Name of the disk}

The “lsof” command, which stands for “list open files,” does exactly what is says: It’s a command meant to list all open files in your system, and dish on the processes that opened them in the first place. Because of this, it’s often used when users cannot unmount (or eject) disks—the command tells you which process is using which file, something you wouldn’t see just by using surface-level macOS. As long as you’ve stopped using the hard drive yourself, you should only see whatever process is holding things up on macOS’ end.

Once you know the process in question, you can terminate it, and safely eject the disk without worry. To do so, you’ll need to open Activity Monitor (press Command + Space then search “Activity Monitor”). Switch to the Disk tab, then scroll through the “Process Name” list until you see the one outed in Terminal. Click on it, then click the (X) at the top of the menu bar. Finally, choose “Quit” on the pop-up to end the process. Now, try ejecting your disk: It should leave your computer right away.

As pointed out by another user in that Reddit thread, the culprit in many cases—at least on macOS—is Quick Look. Quick Look is the feature that allows you to peek at documents, images, and other files without needing to actually open those files first. If Quick Look pops up for you after running this Terminal command, this user recommends you try using Quick Look on another file not on your external disk. For example, open your Mac’s main disk and Quick Look a file there: That process can shake things loose, and allow you to eject your disk without issue.