If you have ever tried to empty the trash in OS X and received a messages saying that it has a locked files and folders, then you know the feeling that no matter what you do, you can’t take out the trash. The files stay behind cluttering up your drive and occupying needed space.
This happened to me when I plugged an external drive into my MacBook Pro and it contained a bunch of old Time Machine Backups. I sent them to the Trash but then I couldn’t empty them from the trash for some reason.
I discovered a solution to this problem and wanted to share it.
Dealing with Locked Files
This actually applies to any file that you can’t move, unlock, modify or copy in Mac OS X. File sin the trash may become locked keeping you from permanently deleting them.
If you’re trying to expunge a file, right-click or Control+click on the file and select Get Info.
The info window will pop-up and you will likely see a check mark next to the word Locked midway down the window.
Uncheck it and close the window.
Now you can do whatever you like with the file.
Dealing with Stubborn Folders
What if you’re trying to remove a persistent folder and get the error message that says you can’t empty the file because of a locked folder? One of the options offers to get rid of all the unlocked content. Select it and then open the Trash to see what’s left. You will likely see the locked folder or folders.
To get rid of the folder or folders, open a Terminal window. I find the easiest way is to press Command+Space to open Spotlight Search box. Type Terminal and hit Enter.
With terminal open, type the following without hitting the Enter key. Remember to NOT hit the Enter key after typing the following line into Terminal:
sudo chflags -R nouchg
Make sure the above line has a space after the last ‘g’ and then open your Trash folder. Drag the offending folder into the Terminal at the end of the line after the space after the ‘g’ and Terminal will automatically enter the text needed to identify folder’s location.
Hit enter and OS X will do its magic on the folder.
Now you can remove the folder by emptyingÂ the Trash. Either choose Finder from the menu and then click Empty Trash â€¦ . You can also use the keyboard shortcutÂ Shift+Command+DeleteÂ which also empties your Trash folder.
If you still can’t remove the folder you have something else wrong. The Apple support page where I found the above solution has a few other possible answers you can try.