The OS X Trash may sometimes give people problems where files cannot be deleted. Usually if you come across a file for which you do not have write privileges, the system will prevent you from moving it to the Trash. But there are instances when odd permissions setups for files can result in bizarre errors when you try to delete them.
One such error may be: "The operation can't be completed because an unexpected error occurred (error code -8003)," but others include a simple warning that you do not have enough privileges to perform the delete action.
Regardless of the specifics of the error, if you cannot empty the Trash, then it is highly likely that in some hidden way you do not have enough privileges to delete the files in the Trash. This usually happens when you are managing files from external disks, but it can happen with any file on the drive.
OS X implements access control lists, which are an extensive way to manage permissions on files, and can sometimes result in bizarre permissions interpretations by the system since you can enter multiple different control entries for a specific user or group account. The entries are inherited and given priority based on when they were entered, which can sometimes lead to extensive and complex permissions rules for a file that stretch way beyond merely allowing "read" and "write" access. For instance, ACLs can allow you to fully read and write to a file, but not delete the file from the system's directory.
When this occurs, the Finder may show the file as being fully accessible by you, but in reality there are more restrictions under the hood, and when you try to delete the file you will be presented with an error. Luckily permissions errors such as this can easily be overcome by emptying the Trash using alternate methods, or even delete and rebuild the hidden Trash folders.
Deleting the Trash
The first method is to use the OS X "Secure Empty Trash" option, which is is available in the "Finder" application menu. This may or may not work, but is worth a first shot.
The second option is to use a utility like "Trash It!" to empty the Trash, which will force the Trash to delete and also rebuild the Trash folders if they are the source of the corruption.
The last option is to use the Terminal to manually perform the same tasks that Trash It will do. This is only recommended for people who are familiar with the Terminal, but can be done by copying and pasting some of the commands here. The commands will remove files using "root" privileges, which if done incorrectly can result in data loss, so be sure you have them entered properly in the Terminal.
Remove the home directory's ".Trash" folder
sudo rm -rf ~/.Trash
This command runs the "sudo" command, which will elevate the rest of the command to the permissions of the super user (the root account) so the remaining command will run unhindered. This can be run before any Unix command to essentially force it to run without errors. The "rm" part of the command is a standalone Unix command for removing files, that is given the options "-r" and "-f," which "recursively" remove files, and "force" them to be removed within the bounds of the current user's permissions. Since we're running this as root, there should be no problem forcing the files to delete.
The last part of the command is the target, where the tilde character represents the home directory, the slash is the root of that directory, and the .Trash part is the target folder.
Remove local filesystem's ".Trashes" folders.
For all of the hard drives mounted on the system, first type the following command, followed by a single space:
sudo rm -rf
This is the same command as above, without the target folder entered. At this point you can drag any one of the mounted disks to the Terminal window to complete the path to that hard drive. It is very important that you do not press enter at this point because doing so will tell the command to delete all files on that hard drive. Instead, we will need to specify the hidden Trash folder to delete.
To do this, you will need to delete the trailing space that was placed in the command when you dragged the hard drive to the Terminal window, and then complete the command with "/.Trashes" so it appears as such (for the Macintosh HD):
sudo rm -rf /Volumes/Macintosh\ HD/.Trashes
With the command set up like this, press enter and the command will complete and remove the Trashes folder at the root of the specified hard drive.
Multiple Trash folders?
You might wonder why the Trash folder in your home directory is called "Trash" whereas the Trash folder at the root of drives is called "Trashes." This is because the one in your home folder is only for you, and files from your home directory that you place in the Trash are put directly in this folder.
On the other hand, files on mounted filesystems are viewable by all users and cannot be copied to your home directory from another drive when you place them in the Trash. Since all users can see these drives, the system calls the Trash folder "Trashes" and creates multiple individual Trash folders within it for each local user account. The folders are labeled with the user ID number of their designated user accounts, and files a specific user delete from this drive are placed in this user ID folder within the "Trashes" folder.