Can't Delete a File on macOS Because It's In Use? Fix
In this article
If you can't delete a file on macOS because it's in use, the fix is to quit the app that's using it, then delete it again. If you don't know which app has it open, use the Terminal command lsof to find the process, then quit it or force-quit it. This article explains the causes, step-by-step fixes, and how to avoid the problem.
Why macOS Says a File Is In Use
macOS prevents you from deleting a file while an app has it open. This is a safety feature: if the file were removed mid-read or mid-write, the app could crash, lose data, or corrupt the file system. The system tracks open files per process, and when you try to delete one, Finder or the rm command gets an error like “The operation can’t be completed because the item is in use.”
Common culprits include:
- Preview or Quick Look holding a PDF or image
- A word processor or text editor with a document open
- Media players (Music, VLC, QuickTime) playing a file
- Apps that keep files open in the background, like cloud sync tools or backup software
- Spotlight indexing or Time Machine scanning (less common, but possible)
How to Find Which App Is Using the File
If you don’t know which app has the file open, you can ask macOS directly. The lsof command lists open files and the processes that hold them.
- Open Terminal (in /Applications/Utilities/).
- Type
lsof /path/to/file(replace with the actual file path). You can drag the file from Finder into the Terminal window to paste the path. - Press Return. The output shows the process name and PID (process ID).
Example output:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME Preview 1234 you 6r REG 1,5 12345 678 /Users/you/photo.jpg
Here, Preview (PID 1234) has the file open. You can then quit Preview normally, or if it’s unresponsive, use kill 1234 in Terminal to force-quit it.
Simple Fixes to Try First
Before diving into Terminal, try these quick steps:
- Quit the app that you think is using the file (Cmd+Q). Then try deleting again.
- If you used Quick Look (press Space on a file), press Escape to close it.
- Close all Finder windows that might have the file selected in a preview pane.
- If the file is on a network drive or external disk, eject and reconnect it, then try deleting.
- Restart your Mac. This closes all apps and releases any file locks. It’s the simplest fix if you can’t identify the app.
Force-Quit the Process That Has the File Open
If you found the process with lsof but it won’t quit normally, you can force-quit it.
- Open Activity Monitor (in /Applications/Utilities/).
- Search for the process name (e.g., Preview).
- Select it and click the X button in the toolbar, then choose “Force Quit.”
Alternatively, in Terminal, use kill -9 PID (replace PID with the number from lsof). This is a hard kill; unsaved data in that app will be lost, but it will release the file lock.
What If the File Is Still Locked After Quitting the App?
Sometimes an app quits but the file remains locked. This can happen if the app crashed and left a stale lock, or if a background process (like a helper tool) still has it open. Try these:
- Run
lsofagain to see if any process still has the file open. If yes, kill that process. - Check for Finder extensions or third-party tools that might be scanning the file (e.g., antivirus, sync apps).
- If the file is on a network share, the lock may be held by another computer. Ask the other user to close it, or disconnect the share.
- As a last resort, restart your Mac. This clears all file locks.
Using Terminal to Delete a Locked File
If you can’t find the holding process, you might be tempted to use rm -f to force deletion. However, rm -f does not bypass file locks on macOS—it will still fail if the file is in use. The only reliable way is to release the lock first. If you’re sure no app is using it, but you still get an error, check file permissions with ls -l. If you don’t have write permission, you can use sudo rm (you’ll be prompted for your password). But be careful: sudo can delete system files if you type the wrong path.
Common Misconceptions and Pitfalls
One myth is that “in use” means the file is corrupted. It doesn’t. It simply means a process has it open. Another is that you can delete a file from the Trash even if it’s in use—you can’t; the same error appears when you empty the Trash. Also, some apps (like Microsoft Word) create hidden lock files (e.g., ~$document.docx) that may remain after a crash. These are usually safe to delete if the app is not running.
Another pitfall: using kill on a system process (like mds or backupd) can cause issues. Only kill processes you recognize as belonging to an app you use.
Frequently Asked Questions
Why does it say “The operation can’t be completed because the item is in use” even after I closed the app?
The app may not have fully quit—check the Dock for a dot under its icon, or use Activity Monitor to see if it’s still running. Also, background helpers (like Dropbox or Google Drive) might have the file open without showing a window. Use lsof to confirm.
Can I delete a file that is in use by a system process?
It’s not recommended. System processes (like Spotlight or Time Machine) usually release files quickly. If you must delete it, wait a few seconds and try again. Forcing a system process to quit can cause instability.
Does restarting my Mac always fix the “in use” error?
Yes, in most cases. A restart closes all apps and releases all file locks. If the error persists after a restart, the file may be on a network volume or have permission issues, not a lock.
What if I can’t even move the file to the Trash?
If the file is on a read-only volume (like a DVD or a locked external drive), you can’t delete it. Check the file’s permissions (Get Info > Sharing & Permissions) and ensure you have read & write access. If not, change them or use sudo in Terminal.
Is there a way to unlock a file without Terminal?
Yes, but only if the lock is a Finder lock (the file’s “Locked” checkbox in Get Info). That’s different from an in-use lock. To remove a Finder lock, select the file, press Cmd+I, and uncheck “Locked.” For in-use locks, you must quit the app—no Finder option exists.