X

Trash solution summary: Cannot delete files

One problem that crops up from time to time is stubborn files that will not move to the trash, or be deleted from the trash when the command is given to do so. There may be errors that accompany these behaviors which include files in use or access denied errors, but at other times there may be no such error.

Topher Kessler MacFixIt Editor
Topher, an avid Mac user for the past 15 years, has been a contributing author to MacFixIt since the spring of 2008. One of his passions is troubleshooting Mac problems and making the best use of Macs and Apple hardware at home and in the workplace.
Topher Kessler
4 min read

One problem that crops up from time to time is stubborn files that will not move to the trash, or be deleted from the trash when the command is given to do so. There may be errors that accompany these behaviors which include files in use or access denied errors, but at other times there may be no such error.

File in use?

One prominent reason for a file being denied access for editing (including deleting it) is if another application is using it and has it locked. This prevents multiple applications from editing the document at the same time (a highly desirable feature) but can result in a trash that will not empty. Try quitting your current applications and emptying the trash, or if that does not work, empty the trash the next time you log out and back in.

Faulty Trash folders

OS X stores trash files on the local boot drive in the hidden "Trash" folder that is within each user account. For external drives, there is a "Trashes" folder at the root of the drive which contains a trash folder for each local user account on the system (designated by UID). If there is a problem with the permissions or other attributes of these trash folders, you may get problems where files delete immediately instead of being moved to the trash. The best way to get around this is to remove the Trash folder(s) and restart the system so the system will recreate them.

For the files on the local hard drive, enter the following command in the Terminal to remove your user account's trash folder:

sudo -rm ~/.Trash

For problems with files on external hard drives, you will need to target and remove the trash folder on the root of those drives, which can be done with the following procedure:

  1. Enter "sudo -rm" in the Terminal followed by a single space.

  2. Drag the desired drive to the Terminal window.

  3. Press the backspace/delete key once to remove the trailing space character (this is important to do).

  4. Complete the command by entering ".Trashes" so the full command looks like the following:

    sudo rm -rf /Volumes/HardDriveName/.Trashes

  5. Press enter, followed by your password to complete the command.

Permissions

The last common reason for stubborn files is permissions, which can be the old and easy to manage POSIX permissions, or the newer and more complex ACL permissions. Many times applications will tack on new ACL permissions for files, which can confuse the system and result in a file that can be read and written to, but not trashed (among other bizarre behaviors).

To get rid of stubborn files, first try using the Terminal to run a direct root-level delete command on the file:

  1. Open the Terminal and type this command, followed by a space:

    sudo rm -rf

    NOTE: I included the "-r" tag in case the file is a folder you wish to delete.

  2. Drag the desired file or folder to the terminal window

  3. Press enter, followed by entering your password.

If the above command does not work, there may be an odd ACL setup on the file or files within a folder that can affect even the "rm" command when run as root. Therefore, try stripping away ACL permissions from the files before deleting them, by using the following procedure:

  1. Open the Terminal and type the following command followed by a single space:

    sudo chown -RN

  2. Drag the desired file or folder to the terminal window

  3. Press enter, followed by entering your password.

Boot Camp trash ghosts?

An old problem that cropped up with boot camp was ghost files with garbled names n the OS X trash that were the result of faults in the Boot Camp volume structure. Reports of these files appearing have diminished, but may still occur for people. If this happens, try running the Windows disk utilities to check and repair the volume structure.

NOTE: The use of "sudo rm" should be used with caution. Only use it if you follow the commands exactly as described in this article, and if you are not comfortable with the Terminal then have someone else do it who is. By all means avoid the following uses of the command:

sudo rm -rf /

sudo rm -rf ~

Basically any time the command targets a slash, it will indiscriminately remove files from that point onward, including any user data, applications, support files, and system files. Therefore, be sure that in any "sudo rm" command, make sure there is no forward slash followed by a single space unless you are targeting that specific directory. Backslashes are ok, since they are escape characters for spaces in file names.



Questions? Comments? Have a fix? Post them below or email us!
Be sure to check us out on Twitter and the CNET Mac forums.