X

Progress bar hangs when emptying trash in OS X

When emptying the trash in OS X, the progress bar may appear to hang. Sometimes this may be because of a hung process, but other times it may be normal behavior.

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

When you empty the trash in OS X, the system will usually present a progress bar showing the number of files remaining to be removed if the number of items in the trash take longer than a moment to delete. Normally this will only take a few minutes and there is some indication that the trash process is working, such as the number of calculated items increasing, or the progress bar moving across the window; however, sometimes the progress window may appear to hang.

Large numbers of files

The time it takes to remove files depends primarily on the number of items being deleted, and at least for the standard trash emptying routine, the size does not matter. When items are deleted, the system will access their entries in the disk's directory and remove them, so the time it takes to remove a file that is 1MB should be the same as it takes to remove a 1TB file.

Even though this is the standard behavior, there are some situations where you may end up removing far more files than what appeared in the trash. For instance, package files on the system may include numerous subdirectories and files that each will have to be deleted if you remove the package itself.

Multilinked files

In addition to packages and other instances of large numbers of files, the system will also take a little longer when managing multilinked files. One situation where this might occur is if you manually remove Time Machine backups when troubleshooting Time Machine. Each backup instance for Time Machine will contain all the files needed to restore your system, and in order to do this without making copies of all the unchanged files between backups, the system will create a hard link in the file system directory for each unchanged file. This results in most of the files on the disk being "multilinked" and resulting in a spider web of file associations in the Time Machine drive's directory.

Because of this, if you try to delete one of these backup instances, the system will have to check the multilinked file and unlink it in addition to managing a large number of files. As a result, the trash progress may appear to go slow or even stall.

Secure empty trash

Finder Preferences
"Secure Empty Trash" can be enabled by default in the Finder preferences as well as in the Finder menu.

The next reason for long trash emptying times is if you have the Finder's "Secure Empty Trash" feature enabled. This feature will have the system not only remove a file's entry from the disk's directory, but also overwrite the file's physical location on disk seven times with random data, to prevent the files from being discovered by data recovery routines.

Generally when you delete files using Secure Empty Trash the system will show each rewrite and subsequent empty as a separate file deletion, resulting in about seven times the number of files to delete as there are files in the trash. If this is coupled to a large number of files, and also if there are multilinked files to be managed, the expected delays for a large number of files will be further compounded by the system have to identify which files need to be securely deleted and which are multilinked files that will not have to be overwritten.

Identifying hung vs normal trash emptying

Regardless of the underlying reason for the slow trash, you can usually check to see if an actual stall occurred by opening the Activity Monitor utility and checking for activity in the process called Locum. This process is a tool that is hidden in the Desktop Services framework, which is used by the system for emptying the trash by gaining specific permissions from the user and then holding them so files in the Trash can be managed without interference.

For instance, if files in the trash are locked, you can hold the Option key down when emptying the trash to delete the locked files. This gives the Locum process permission to remove any locked file without prompting the user each time.

Since the Locum process is used to empty the trash, as long as it is working in Activity Monitor then you can assume the trash is being emptied properly and the system has not hung. Give the process time to finish, which depending on the deletion job at hand can take numerous minutes or even hours.

If the Locum process is showing 0 percent activity, cannot be found, or is colored red, then the deletion process for the trash is hung up and will need to be restarted. Using Activity Monitor you can try forcing the Locum process to quit, and also force the Finder to relaunch and try emptying the trash again. If the process still fails, then it is likely some file in the trash or corruption in the trash folder is causing the hang. To fix this your best bet is to remove the hidden trash folders by running the following commands:

Home folder trash file (for the individual user):

rm -rf ~/.Trash

Global "Trashes" file for the main boot drive (this will require you to enter your password--not shown):

sudo rm -rf /.Trashes

Global "Trashes" file on non-boot volumes:

sudo rm -rf /Volumes/"NAME"/.Trashes

In this last command, substitute NAME for the exact name of a nonboot hard drive on your system (external or internal), leaving the quotes in the command. Do this for each drive on the system and keep in mind that for all these commands if you have a large number of files then they may take a long time to complete. The difference here is that the "rm" command uses less checks than the Locum process, and being simpler will likely be more successful at removing the desired files.

Once the trash folders are removed the system will recreate them when they are needed.



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