Force Empty Trash in Mac OS X When File is Locked or In Use
Mac OS X can sometimes throw permissions errors when trying to delete files or empty the Trash. The most common variations of the errors are usually “Operation cannot be completed because the item “File” is in use” or “because the file is locked”, sometimes you can get around this by just quitting open applications or rebooting the Mac, but if you don’t want to do either you can also forcibly remove files through the command line. We will cover two different approaches to this, the first changes a files flags to attempt to unlock the file in question, and the second is a no-nonsense force delete.
First: Try quitting all apps to release the file lock or permissions, then attempt to Secure Empty Trash by holding down the Command key and right-clicking the Trash icon. If that doesn’t work, proceed with the methods outlined below. Some users have also reported Command+Shift+Option+Delete to work as a method of forcing the Trash to empty regardless of a file being locked or owned by another user.
Change Permissions To Forcibly Empty Trash
The first approach uses the chflags command to change the flags of all files in the Trash
Launch Terminal found in /Applications/Utilities/ and then proceed:
cd ~/.Trash
chflags -R nouchg *
Now you can try emptying the Trash as usual through the Dock, a keyboard shortcut to dump the file, or go the rm route mentioned below.
Advanced: Forcibly Emptying the Trash via Command Line
This is a last resort and intended only for advanced users. Make sure the syntax is correct with this, the “sudo rm -rf” command will erase anything without warning. If you don’t know what you’re doing you could easily delete crucial system or personal files. Have backups ready or don’t bother with this method, proceed at your own risk.
First change the directory to Trash:
cd ~/.Trash
Confirm you are in the proper directory and the only files you see are the ones you want to forcibly remove by using ls:
ls
Now try to delete the specific file:
rm filename.jpg
If that still doesn’t work you can try the ultimate delete approach using sudo and -rf *. This is intentionally not spelled out easily to try and prevent any novice users from accidentally deleting something significant.
Using sudo requires the administrator password but combined with rm it will absolutely forcibly remove any file regardless of whats going on with it.
I have a huge list to delete
Apple drives me crazy!!!
I have a copy of iTunes in my Trash. I have tried everything listed here. When I use the Terminal it gives me the message that “Operation not permitted” for each piece. I am fully updated to High Sierra. Can’t take iTunes out. When I use the Delete Immediately command, it disappears and then pops right back in. Driving me nuts!
i found Trash It did the job.
I am not a power user, but I can use the the Terminal. I had erased a ext HD by dragging contents to Trash and then trying to delete.
Going thru all the various ideas and steps above and four hours of typing commands, this is what finally emptied my trash. I found I had to use complete PATH for the trash, copying or typing did not work. why not? I just dragged the folder icon from my trash window onto the terminal.
Using sudo,
1. enter cd and drag the folder from the trash to terminal. Run.
2. Then enter chflags -R nouchg and again, drag the folder from the trash to terminal. Run. I had a years BU so it took almost an hour to finish resetting permissions.
3. then enter rm -rf and drag the folder from trash to the terminal once more. Run.
It took a while but finally, my trash is empty
This is on an iMac with Sierra.
Mick
This worked for me.I inserted a pendrive then I dragged 3 items(which,I was not able to remove from trash even after trying everything stated above.) to my pendrive.
The trash got empty and I formatted the pendrive in other os.(you can do it in mac also.)
If you don’t want to format the pd then just take all the items from trash and delete those in some other os like windows.
I tried every single one of these commands, all the way up to the sudo command. NONE will delete the files. When I ran the sudo command, I got this error:
Steves-iMac:.Trash stevejones$ sudo rm -rf*
Password:
rm: illegal option — *
usage: rm [-f | -i] [-dPRrvW] file …
unlink file
Steves-iMac:.Trash stevejones$
The trash contains 8 folders with names such as “2015-10-21-074257” in each folders is another folder “Macintosh HD” (the name of my HD) and in that is a folder “Applications” and in that is the app Crashplan.app but the icon is the greyed out slash in a circle on a document – it is not an app that will pen.
You should update OS X and reboot your Mac, your problem will probably be fixed.
Aside from that, it’s not working because you are not typing the proper syntax. You need a space between f and * but realistically if you can’t follow instructions then you absolutely should NOT be using the Terminal let alone the rm command with a * (anything) wildcard which can delete any and all files on your Mac without any confirmation. rm is extremely dangerous for novice users, you can easily delete anything permanently with it if the syntax is not exactly precise. Why risk it? I would advise not to use the terminal at all, just reboot your Mac and empty the trash as usual.
Back up your Mac with Time Machine first, don’t skip a backup.
cd ~/.Trash/;rm -rf ~/.Trash/*
Hopefully you are making regular backups of your Mac.
Wow – thanks for the condescending response. I also tried it with the space in it and Terminal just goes back to the prompt and the trash is NOT emptied. The OS is FULLY updated – so that is not going to help, is it? Just reboot the Mac and “empty the trash as usual”? LOL. Really? Did you at all read what I wrote? AGAIN – I have tried EVERY option listed in the thread. NONE of them will remove the files. The files appear to all be (I’m guessing a bit here) Time machine backup folders of a broken/deleted/screwed up app called “Crashplan.app” since it appears in every folder hierarchy with the cycle/slash icon and has an app size of “Zero bytes”. If anyone has any suggestions, other than chastizing someone who has been a Mac user for over 25 years, please chime in.
Well, my hunch on what the files were appears to be correct. They were Time Machine files. But I couldn’t drag them out of the trash – they just COPIED out and left the originals in the trash. And I couldn’t empty the trash using ANY of the methods outlined above. NONE of them worked. So I backed up my HD to a separate drive and then formatted my backup drive with Time Machine on it – and *poof* the files in the trash were gone. They were tied to that backup drive and yet wouldn’t delete. So now I have a cleaned main backup drive that is starting the Time Machine backups over again and an extra drive that is holding my data as an extra backup until Time Machine completes “resetting”. Thanks goodness I back up regularly. *sarcasm on* And thank goodness Ohno chastised me to do so. *sarcasm off* Even though I have backed up every Mac I have ever owned.
Im sure Steve is over this by now but for anyone else having his experience he missed a space. Simple mistake.
The command should read
sudo rm -rf ~/.Trash/*
-rf are the flags for recursive and force respectively
the space is needed because the star is a wild card for any combination of characters basically any file from this directory and because of -r any other directories below this one. So it is not an option it is the file.. part of his usage message from above.
Command+Shift+Option+Delete!!!!! Thank you!!
open the trash folder. right click on the stubborn file and select delete immediately.
When this happens, I usually restore the file to its original location, and then use terminal to delete the file via: “rm XYZ”, never fails.
Cheers,
John
non-pc.org
Lovely. Thank you. This worked so easily
Sometimes changing the file ending works very well when file is in use.
i tried sudo and chflags and everything you mentioned, it doesn’t work, they all give me “No such file or directory”
anybody can figure this out??
Thanks it works !@!@@!@!!
Thanks it works
Wow… I have one bloody stubborn file…
It’s on my external hard drive where I store all my iTunes stuff. Took a while to track it down but finally managed to do so. Turns out I had to cd to
“/var/volumes/Seagate Expansion Drive/Trashes/501/”
But Finder reports it as
“/var/volumes/Seagate Expansion Drive/Trashes/Trash/”
Anyway, eventually got to there. Tried the whole change flags thing and it just said Input/output error
So I tried renaming it… Same thing.
Finally had enough and went the dangerous route… with the sudo rm -rf option and STILL I got the same thing. That bloody file just refuses to die!!!
I still can’t delete a folder in my trash. The fiolder in question is actually on an external WD hard drive, thus only show up in trash when I plug it in. I have tried everyhting to delete them – all the advice here has been attempted…
Secure Empty gives me: “The operation can’t be completed because you don’t have permission to access some of the items”
sudo etc doesn’t seem to delete them either
Help!
Command, option, shift, and right clicking the trash to secure empty worked for me too…there aren’t enough thank yous to go around!
Here’s to getting rid of those pesky locked files in the trash, whew!
Change Permissions To Forcibly Empty Trash
Thank you it worked for me.
how do you changed permissions to forcibly empty trash?
If you don’t want to Terminal bash it, you can try right clicking on the file while it’s in the trash, then press cmd and choose Empty Trash. This works 7/10ish is the file is persistent with just a regular emptying.
Failing that, I use the app Find Any File. Copy the file’s name that needs deleting, and paste it into Find Any File. Once found, right click on the file and choose “Delete Immediately”. Works a charm.
Thanks, it worked out perfectly!
I tried every method I could find and couldn’t get rid of a locked file deleted from Time Machine. Then I ran routine cleaning with OnyX and it deleted it with no fanfare.
I have tried using the command suggested but my problem is that every time I start a secure empty trash it stops after a few seconds and doesn’t delete any files,
DUDE!! Thank you for posting this. Very clean way to tidy up the stuck on trash! You rock.
Numerous utilities will do this all for you with the click of a button. Onyx being one of them, MainMenu another.
try using this command,
rm -rf ~/.Trash/*
i was working on this last night but fall asleep not finishing the job. so i woke up the next morning and the first thing i did, terminal x…rm -rf *. woooooops wrong dir, here i am trying to fix it…
I tried everything!! Then paydirt!! Just went to disk utility and repair permissions. Viola!!
you only need:
cd .Trash/
rm -rf *
check your current directory and be sure to be in ~/.Trash, if you run the command rm -rf * in a wrong place and wrong user, prepare do reinstall your system.
Perfect. So simple. Dangerous if you don’t change directory to Trash, but if you don’t know to do that, you shouldn’t be messing about in Terminal in the first place.
you are the boss
thnx
To Trevor and Anonymous… and this web site/comments… Thank You! I have been working for two days trying to delete locked files from the Trash on my iMac running OS 10.8. Nothing worked until I came across this list of comments. I tried everything and I mean everything, but nothing worked. I will add that after I was able to delete the locked files holding down the Command Key. I then went back and added the Admin and myself to the permissions list and changed everyone’s permission listed to Read & Write. Then I held down the Shift, Option & Command key right clicked the Trash and Bam… they were all deleted. Thank You Again!
excellent thanks – so frustrating trying to get rid of stuff!
In most cases, I just try again, and it deletes without incident.
If it complains about the file being in use you can also “lsof | grep filename” and see what program is using it so you can close it. Worked every time for me.
just press Command Option Shift and Delete and it will empty the trash even if the file is owned by another user
Good man! After trying Terminal and all the suggestions on another site trying to delete old Time machine Back Ups Command Option Shift and Delete the trash worked.
Thanks Anonymous
I have tried everything as well … And this was the ONE thing that completely erased my Trash Box! Thank YOU!
I have tried EVERY tip before and this is the only thing that would completely empty my trash. Thank you!!!
Thank you!! Thank you!! Thank you!! Muchly appreciated.
sweet jesus thank you this is the only thing that has worked for me
Finally something that works! Thanks
is no one reading the web, the shortcut is already written on the second para on this web
Brilliant – worked perfectly. The locked files remained in the Trash and built up until I used your suggestion. Thanks.
nice! very quick too
I just always right click the trash and hold command key to secure empty. Works every time to overwrite error.
Good job Trevor, even the guys at the genius bar here in Naples didnt know that trick:-) worked perfectly!
I usually just use TrashIt! It’s free.
tried trash it, but not working!
Used it for a stubborn locked file and worked perfectly.
I second that. TrashIt NOT working in either FAST or REALLY STUCK mode. My two items remain in the Trash, even after trying to reset permissions with the Terminal as well as MacDentro’s IceClean. I also tried Force Empty Trash AND holding down the Option key while trying to empty the Trash. No luck. Sigh. Can no one help??