Force Empty Trash in Mac OS X When File is Locked or In Use | OSX Daily

Trash Can Up Side Down

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:

cd ~/.Trash

chflags -R nouchg *

Now you can try emptying the Trash as usual through the Dock, 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:

cd ~/.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:

ls

Now try to delete the specific file:

rm filename.jpg

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.

Via: Force Empty Trash in Mac OS X When File is Locked or In Use

Advertisements

One thought on “Force Empty Trash in Mac OS X When File is Locked or In Use | OSX Daily

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s