Force Empty Trash in Mac OS X When File is Locked or In Use
Mac OS X can sometimes throw permissions errors when trying to delete files or empty the Trash. The most common variations of the errors are usually “Operation cannot be completed because the item “File” is in use” or “because the file is locked”, sometimes you can get around this by just quitting open applications or rebooting the Mac, but if you don’t want to do either you can also forcibly remove files through the command line. We will cover two different approaches to this, the first changes a files flags to attempt to unlock the file in question, and the second is a no-nonsense force delete.
First: Try quitting all apps to release the file lock or permissions, then attempt to Secure Empty Trash by holding down the Command key and right-clicking the Trash icon. If that doesn’t work, proceed with the methods outlined below.
Change Permissions To Forcibly Empty Trash
The first approach uses the chflags command to change the flags of all files in the Trash
Launch Terminal found in /Applications/Utilities/ and then proceed:
chflags -R nouchg *
Now you can try emptying the Trash as usual through the Dock, a keyboard shortcut to dump the file, or go the rm route mentioned below.
Advanced: Forcibly Emptying the Trash via Command Line
This is a last resort and intended only for advanced users. Make sure the syntax is correct with this, the “sudo rm -rf” command will erase anything without warning. If you don’t know what you’re doing you could easily delete crucial system or personal files. Have backups ready or don’t bother with this method, proceed at your own risk.
First change the directory to Trash:
Confirm you are in the proper directory and the only files you see are the ones you want to forcibly remove by using ls:
Now try to delete the specific file:
If that still doesn’t work you can try the ultimate delete approach using sudo and -rf *. This is intentionally not spelled out easily to try and prevent any novice users from accidentally deleting something significant.
Using sudo requires the administrator password but combined with rm it will absolutely forcibly remove any file regardless of whats going on with it.