A file is still in use when trying to empty the Trash – how can I remove it?
When you try to empty the Trash in OS X, and there is a file still open in an application, you receive the dialog:
The operation can't be completed because the item "…" is in use.
How can I find out which application or which process still uses this file?
Using lsof
to find what's keeping the file open
Open up Terminal.app and use the following command to get to your Trash:
cd ~/.Trash
Now, enter the following command:
lsof name-of-file
For example, in the above screenshot, it would be: lsof pdf\ 08-53-59.pdf
(important to escape spaces here). You can also just enter lsof
with a space afterwards, and then drag the file from Finder's Trash into the Terminal window.
The command will output something like the following:
charon:.Trash werner$ lsof pdf\ 08-53-39.pdf
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Finder 5022 werner txt REG 14,2 636141715 32494023 pdf 08-53-39.pdf
In that case, we know that Finder is keeping the file open. For any other application, it would be easy to just activate and quit it. In case of the Finder, there's no obvious "quit" button.
To kill the Finder and release the document, just enter the following in the Terminal:
killall Finder
You should now be able to empty your Trash.
Other tricks
If the above does not succeed, here are some very basic tricks you can try to empty your trash:
- Log out from your user, and log in again
- Reboot the Mac, log in again
lsof
didn't return anything for me even with sudo. But simple rm
did the trick.
cd ~/.Trash
In my case it was app so:
rm -rf some.app