4

I am on Yosemite (10.10.1) and I noticed the annoying habit of not wanting to empty the trash -- it keeps whining that The operation can’t be completed because the item “whatever” is in use. This is starting to piss me off - I can go to .Trash and remove stuff by hand, but is going on? Once a file is not in use and has been binned, why can't the OS recognise it's not actually linked to any application? This problem has come up whether the app used for that kind of file is still open or not btw.

  • 2
    FWIW if you KNOW that it is just OS confusion, you can always secure empty trash. – dwightk Dec 9 '14 at 21:14
  • 1
    Secure empty trash won't delete anything that regular empty trash won't delete. Holding down the option key when emptying the trash will allow locked files to be deleted, but still won't delete in-use files. – ganbustein Dec 9 '14 at 22:34
  • 1
    Not an answer... but it is really bad design when an application puts a file in the trash and yet still marks it as used. Somewhere along the way, that is wrong behavior. Since it started happening with Yosemite, I am inclined to blame it on the OS. It would be interesting to hear what applications were responsible - would you be so kind as to update your question with your findings (since it appears that ganbustein's answer helped you...)? – Floris Dec 10 '14 at 1:10
  • Who says the app that's using it is the one that put it in the Trash? – ganbustein Dec 10 '14 at 19:35
  • I will keep a tab on this question and update with the culprits -- thus far Preview has the highest score. – user1256923 Dec 10 '14 at 23:03
9

To find out what file(s) in your Trash are in use, and by whom:

lsof +D ~/.Trash

The command name in the first column will be truncated. If it's truncated so much that you cannot identify the process, the second column contains the pid (Process ID), which you can cross-reference in Activity Monitor. Or get additional info using ps -p pid.

Note:

It has been suggested that the command:

sudo rm -rf ~/.Trash

may be useful here. This is not the case!

If a file is in use (which is the scenario the question is about), it cannot be removed! Not even by root.

The suggested command may be useful if:

  • You are in an admin account (or in sudoers, which I discourage as a security weakness), and
  • The only reason you cannot remove the file is that its permissions deny deletion.

In general there are three reasons why you might not be able to empty the trash, and each reason has its own cure.

  • If the file (or folder) is locked, you can either unlock it or hold down the option key while emptying the trash.

  • If permissions do not allow you to remove the file, you can either change the permissions to allow it, or use sudo to override the file's permissions.

  • If the file is in use, your only recourse is to find the process that is using the file and make it stop using it. In the simplest case, trying again after a short wait is all it takes. It may be necessary to force quit the app, and the purpose of the lsof command is to determine which app needs to be quit. However, even root cannot remove a file that is in use.

The takeaway is that the problem "I cannot empty the trash" does not have a one-size-fits-all solution. When you are told that something is in use, do not waste time trying to apply a fix that doesn't fit that situation.

I have also seen it suggested that Secure Empty Trash may be helpful. Again, this is not the case! Secure Empty Trash will overwrite the sectors on disk that the file's data was stored in, but only after the file is successfully deleted. If you can't delete the file, for whatever reason, it won't be deleted or overwritten. If the file is hard-linked, deleting it only deletes one of its links. As long as other links remain, the underlying inode is not deleted and the file's disk space is not overwritten.

3

It does mean that file is in use, so removing it may affect the application which is using it. you can use lsof or fs_usage to monitor what process is using them e.g.

$ lsof -T|grep Arial
Skype       311 auniyal  txt      REG                1,4     774476  499182 /Library/Fonts/Microsoft/Arial.ttf

You must log in to answer this question.

protected by Community Aug 21 '15 at 21:37

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged .