Friday, November 11, 2011

Two solutions for MacOSX "The operation can’t be completed because the item is in use."

I get that error quite often and quickly discovered a "fix" to empty the trash anyway.
The only problem is that I want to understand who is using this file and why it is still using it when there is no apparent task running.

You try to empty your trash, you get an error
"The operation can’t be completed because the item XYZ  is in use."

You check with Command-Tab and there s nothing running except Finder. Who the hell is using this file?

Here comes the dreaded Terminal. Don't be scared it is just another way to control your computer, if you are careful there is no problem.
  1. Open Terminal (you can type "Terminal" in SpotLight (Top right magnifier)
  2. Type
     lsof | grep   Don't type Enter yet
      lsof  is a command that lists open files 
  1. Try to empty the trash again and copy the filename (-C) from the error message
  2. Return to Terminal and paste the name of the file using -V (Command-V)
  3. If the filename contains spaces and special characters enclose in quotes as below

    lsof | grep "file that cant be deleted.png"   <enter>
  4. You should see something like this:
MyMac:~ guest $ lsof | grep "Screen shot 12.30.28 PM.png"
Mail 63367 guest ... /Users/guest/.Trash/Screen shot 12.30.28 PM.png

See?  Mail is using the file, that's why I can't delete it. In your case it could be any other application. The name of the application is first on the line.

Now that you know the app that keeps your file opened you can do one of three things:
  • You need the file and will have to put it back where it belongs
  • You can Close the app using it.
  • You don't need the file and want to delete it anyway! Force delete.
Force Delete 

Careful this one is no return.

  • Command Right click on your trash
  • Select Secure Empty Trash

This should do it. If it doesn't work it is generally caused by Sharing and Permissions on the file

Change Sharing and Permissions on a file

Sometimes, when copying files from external drives, removable USB sticks etc, files are copied with strange permissions, often they are Read-Only or you are not the owner.

To see who owns that file and what permission you have, select the file in the trash or finder
Command-I  or Right Click > Get Info
At the bottom in the Sharing & Permissions you see who owns the file and which rights you have

To delete a file you should have Read-Write privileges

  • Unlock the file by clicking on the small closed padlock and entering your password
  • Change the file privilege to Read-Write if Read-Only
  • If your name is not there add your user name by clicking on + and a selecting your name, then select read write
  • Now you should be able to delete the file
Other method (Apple recommended but long)

Using DiskAid and Repair permissions you can fix most of permission issues. This should be done once a month if you move a lot of files to and from external USB drives. 

Check the Apple support document: Troubleshooting permissions issues in Mac OS X 

Mad*

PS: When you run command in Terminal  Control-C will terminate the command and return to the prompt. Don't forget to close Terminal after using it!

5 comments:

  1. hey i have a really weird problem. ive got this files in my trash that just refuse to delete. ive tried all options on internet and it comes up with the message "The Finder can’t complete the operation because some data in “asfdas” can’t be read or written. (Error code -36)" there are also weird files "e-, Öˆ` .± ä" and "é®?üL ␀␀.␀␀␀" and like 30 others like that. i really want to get rid of them but dont know how.

    ReplyDelete
  2. I generally don't like to see files with strange characters like these. Most apps won't create files like these (generally) and it is a sign of either an app that went crazy, a virus, or a Disk in the process of failing. Error -36 means "Disk IO Error" which could point to a failing drive.

    I would do a "Verify" Using "Disk Utility" to check if the drive is OK first.

    Now MacOSX can't delete files that contain strange characters, so the recommended procedure is to rename one by one each file to a "Normal" name like file1 file2 etc.... then try an "Empty Trash".

    If drive is failing and you don't have a Time Machine backup, it is time to backup your important stuff to an external USB disk or thumb drive. I do all my backups with "Disk Utility".

    WIth MacOSX Lion and Mountain Lion we can't backup the system drive while system is accessing it, and you have to boot in recovery mode then use the "Disk Utility" to backup. Check here for more:
    http://www.apple.com/osx/recovery/

    If you have a serious drive problem (clicking noise) I would recommend a visit to the local Apple store.
    Good Luck !

    ReplyDelete
  3. Thank you, thank you, thank you, thank you.

    ReplyDelete
  4. I was trying to delete a file and the terminal said it was being used in Quicklook. Quicklook was not open when I looked at the list of applications I could force quit. It turns out I had to change the finder from the cover flow view to list view. Not sure why it worked. It would let me delete other items in the cover flow view. But, problem solved.

    ReplyDelete
  5. Yes you forced a refresh by doing that. In extreme cases Force Quit Finder also works

    ReplyDelete