Use This Terminal Command to Force Eject a Hard Drive From Your Mac

We’ve all been there: you have an external hard drive or USB stick connected to your Mac and you’re ready to part ways. You drag it to the trash or right-click to eject it, only to be greeted by the infamous “The disc has not been ejected because one or more programs may be using it.” You look around your Mac: no apps are open, no programs are running. Whatever is causing ejection delays, it’s definitely not your fault. In the wise words of Peter Parker , “I missed the part where this is my problem.”

Unfortunately, macOS has made this your problem. There can be several reasons why your computer won’t release your drive ( we’ve covered them before ), but often the root problem is this: macOS launches a process accessing a file on the drive that you can’t see. That’s why even though everything is off and closed, as far as you can see, your Mac insists that the disk is in use. We all find it hard to let go sometimes.

However, your Mac doesn’t always leave you unattended: sometimes you’ll see an option to force eject the disc, but even this solution has one caveat: how do you really know that your Mac isn’t currently writing something to the disc? If you forcefully eject it, either through software or by unplugging the drive from your Mac, you could corrupt its data.

Luckily, there’s an easy fix if you’re okay with Terminal. In a Reddit thread reflecting on the subject , one user suggested the following command to quickly end any unknown processes running between macOS and your hard drive:

sudo lsof /Volumes/{Disk name}

The “lsof” command, which means “list open files,” does exactly what it says: it’s a command designed to list all open files on your system, and primarily the processes that have them open. Because of this, it’s often used when users can’t unmount (or eject) drives – the command tells you which process is using which file, which you won’t see just using surface-level macOS. Until you stop using the hard drive yourself, you should only see what process is holding up on the macOS side.

Once you know what the process is, you can complete it and safely eject the drive without worry. To do this, you need to open Activity Monitor (press Command + Space , then search for Activity Monitor). Click the Disk tab, then scroll through the Process Name list until you see the one displayed in the Terminal. Click on it, then click (X) at the top of the menu bar. Finally, choose Exit from the pop-up window to end the process. Now try ejecting the drive: it should leave your computer immediately.

As another user pointed out in this Reddit thread, in many cases the culprit – at least on macOS – is Quick Look. Quick View is a feature that allows you to view documents, pictures, and other files without having to open them first. If you get a Quick Look popup after running this terminal command, this user recommends that you try using Quick Look on a different file than on your external drive. For example, open your Mac’s main drive and take a quick look at the file: this process can shake things up and allow you to eject the drive without problems.

More…

Leave a Reply