Can't eject USB drive on Mac? Find which app is using it (lsof)
Mac says your USB drive or SD card is in use after you quit everything? Use sudo lsof to find the holder, handle Spotlight's mds, then eject safely.
GuideUpdated 7 min read
On this page
You closed every window, and Finder still says the drive can't be ejected because it's in use. Or it gives no reason at all. That is a common situation with USB drives and SD cards, and the fix is to ask macOS which process has files open on the volume instead of guessing.
Why a drive won't eject
A volume can only unmount when no process has a file or folder open on it. Apple's support page says you may not be able to eject a disk if one or more apps are using it, and a warning message may sometimes identify the app. When it doesn't, the holder is usually one of these, most common first:
- A Terminal tab sitting inside the drive. A shell whose current folder is on the volume keeps it busy.
- Finder or Quick Look. A Finder window or tab showing the drive, a Preview window, or a Quick Look panel for a file on it.
- An app with a file open. Photo import tools, backup apps, editors, media players and cloud sync clients.
- Spotlight (
mds,mds_stores). Spotlight indexes newly mounted drives, and ejecting soon after you plug one in can hit it. This is the usual cause of "I closed everything and it's still busy". - A background helper or a copy that hasn't finished. An app can keep a helper process running after you close its window.
Some causes are not known in advance. Sometimes lsof shows nothing at all; the last sections cover that.
Quick fixes first
These take under a minute.
- Close every Finder window and tab that shows the drive's contents.
- In each Terminal tab, run
cd ~so no shell is inside the drive. - Wait for any copy, backup or import to finish.
- Quit the apps that use the drive. Apple's guidance is to close the documents on the disk if you can't quit an app. Command-Tab shows which apps are open.
- Eject again: use the eject button in the Finder sidebar, or Control-click the drive and choose Eject.
If it's still stuck, find the holder.
Find the holder with lsof
lsof ("list open files") ships with macOS. It reports which processes have files open. Use sudo: without it, lsof only shows files you have permission to examine, so root processes such as mds won't appear.
Open Terminal (Applications > Utilities).
Type
sudo lsofwith a trailing space, then the drive's path. Quote it if the name has spaces:bash sudo lsof "/Volumes/My Drive"You can also drag the drive's icon onto the Terminal window and it pastes the path.
Press Return and enter your password. Nothing appears as you type.
Given a mount point, lsof lists open files on that whole volume. It only reads and changes nothing. If you aren't sure of the exact name, run ls /Volumes.
The output has columns including COMMAND, PID, USER, FD and NAME. This is an illustrative example with columns trimmed, not real output:
COMMAND PID USER FD TYPE NAME
mds 112 root 5r DIR /Volumes/My Drive
zsh 4310 you cwd DIR /Volumes/My Drive/PhotosTo list open files under one folder recursively, use sudo lsof +D "/Volumes/My Drive". It can be slow on a large drive. Lowercase +d only checks the folder's immediate contents.
Read the COMMAND column
| COMMAND | Meaning | Fix |
|---|---|---|
mds, mds_stores | Spotlight is indexing the drive | Add the drive to Search Privacy (next section) |
Finder | A window, preview or copy uses it | Close windows showing the drive |
zsh, bash with cwd in FD | A Terminal tab is inside the drive | Run cd ~ in that tab |
| An app you know | The app has a file open | Quit it normally; force quit only if it hangs |
For a hung app, see our guide on how to force quit on a Mac.
If it is mds: stop Spotlight indexing the drive
Excluding a drive in Search Privacy tells Spotlight to leave it alone, which releases it.
- Open System Settings and click Spotlight in the sidebar. Apple's page says it may be labeled Siri & Spotlight on some versions, and you may need to scroll.
- Click Search Privacy… (on macOS 14 it is labeled Spotlight Privacy).
- Drag the drive into the list, or click the add (+) button and select a folder or disk.
- Click Done.
- Eject the drive.
Apple documents these steps in its page on preventing Spotlight searches in specific folders or disks.
If the drive is still busy, run lsof again. If mds is still listed, end it using the PID from your output (here 112):
sudo kill 112This sends a normal termination request to that one process. macOS restarts mds on its own. Run lsof once more to confirm the drive is clear, then eject.
To undo the exclusion, open Search Privacy… again, select the drive and click the remove (−) button. Spotlight then indexes it again, so files on the drive will be searchable once more.
Eject from Terminal
diskutil can unmount by path, and its error message may name what blocks it:
diskutil unmount "/Volumes/My Drive"To power down the whole device afterwards, use diskutil eject "/Volumes/My Drive".
Which method shows what is holding the drive
| Method | Shows the holder? |
|---|---|
| Finder eject | Sometimes names an app in its message |
sudo lsof | Yes, including root processes such as mds |
diskutil unmount | May name the blocker in its error |
| Procowl | Your own processes only, not root processes |
Where Procowl helps (and where it doesn't)
We make Procowl, and it covers only part of this. It can eject a volume and show the open files of your own processes. It can't see what root processes hold, so it won't show mds. For that, use sudo lsof.
- Eject button: open the Disk tile on the Overview, then use the eject icon on the drive's row under Volumes. If macOS refuses, Procowl shows a "Couldn't Eject" alert. Network volumes aren't listed.
- Open files of your own processes: in Processes, select a suspect app and open the inspector. Under Open files, click Show List. It shows up to 80 entries plus "+ N more". A path under
/Volumes/YourDrivemarks the culprit. - Programs running from the drive: type
/Volumes/in the search field. Plain text matches process paths, so anything executing from the drive shows up. - Limit: even with the optional Enhanced Access helper, Procowl doesn't show open files for root processes.
Details are in the Procowl disk docs and inspector docs. Procowl is part of MacSuite, and you can try it free for 7 days.
Checklist before you try again
- No Finder window or tab shows the drive.
- No Terminal tab has its current folder on the drive.
- No copy, backup or import is running.
sudo lsof "/Volumes/My Drive"lists nothing, or only things you have dealt with.- The drive is excluded from Spotlight if
mdswas the holder.
If nothing works
- lsof shows nothing, but Finder says it's in use. Wait a minute for a write or Spotlight pass to finish, then run
diskutil unmountand read the message. - The process keeps coming back. An app with a sync or background helper reopens files. Quit it from its menu, not just the window, then re-run lsof.
- Another user is logged in. Apple says to log out the users using the disk, or restart your Mac if you can't.
- Last resort. Shutting down releases the drive.
If the drive disconnects or can't be read at all, the cause may be the drive, cable or port. Contact Apple Support or the drive's maker with this:
My Mac won't eject my USB drive / SD card ("in use" message).
macOS version:
Drive name and format:
Output of: sudo lsof "/Volumes/<drive name>"
Output of: diskutil unmount "/Volumes/<drive name>"
Already tried: quit all apps, cd ~ in Terminal, excluded the drive from Spotlight.Common questions
Is it safe to pull the drive out anyway?
It risks corrupting files if anything is still writing. Eject first. If you already pulled it, plug it back in, check that your important files open, and copy them off.
Does this work for SD cards?
Yes. An SD card in a reader mounts under /Volumes like a USB drive, so the same lsof, Spotlight and diskutil steps apply.
Why does it happen right after plugging a drive in?
Spotlight starts indexing a newly mounted drive, so ejecting soon after connecting can run into mds in the lsof output.
Why do I need sudo for lsof?
Without it, lsof only lists files you have permission to examine. Spotlight runs as root, so you need sudo to see it.