Use This Terminal Command To Force Eject A Stubborn Drive From Your Mac

Use This Terminal Command To Force Eject A Stubborn Drive From Your Mac

Image from article titled Use This Terminal Command To Force Eject A Rogue Drive From Your Mac

Photo: The party of the image (Shutterstock)

We’ve all been there: You’ve got an external hard drive or USB stick plugged into 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 disk was not ejected because one or more programs may be using it.” You look around your Mac: no applications are open, no programs are running. Whatever is causing the ejection delays is certainly not your fault. In the wise words of Peter Parker“I missed the part where that’s my problem.”

Unfortunately, macOS has made it its problem. There could be multiple reasons why your computer won’t release your drive (we have analyzed them before), but often the main problem is this: macOS is running a process to access a file on disk that it can’t see. That’s why, even though all is off and closed as far as you can see, your Mac insist the disk is in use. We all have a hard time letting go.

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

Fortunately, there is a simple solution, as long as you’re okay. using Terminal. in s Reddit thread reflecting on this topicOne user suggested the following command to quickly kill any unknown processes running between macOS and your hard drive:

sudo lsof /Volumes/{Disk name}

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

Once you know the process involved, you can end it and eject the drive safely and without worry. To do this, you’ll need to open Activity Monitor (press Command + Space then search for “Activity Monitor”). switch to the Disc then scroll through the “Process Name” list until you see the one appearing in Terminal. Click on it, then click the (X) at the top of the menu bar. Finally, choose “Exit” in the pop-up window to finish the process. Now try to eject your drive: It should come out of your computer right away.

As another user pointed out 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 take a look at documents, images, and other files without opening those files first. If Quick Look appears for you after running this Terminal command, this user recommends that you try using Quick Look on another file No on your external drive. For example, open your Mac’s main drive and quickly find a file there — that process can shake things up and allow you to eject your drive without a hitch.


Leave a Comment

Your email address will not be published.