[HOWTO] - Empty the trash of stubborn items


Help Guide Coordinator
This How-to submitted by: testuser.
Thanks for the contribution.

Sometimes when trying to empty the trash we run up against an
"Insufficient privileges" error that prevents us from deleting junk
files. I wrote a simple shell script that can be run from the
terminal to empty the trash when the Finder will not permit us to do

I suggest creating this shell script using a text editor like BBEdit
Lite ( http://www.bbedit.com/bbedit_for_X.html ), or with your
favorite text editor in the Terminal. First, make a new folder in
your home directory entitled "bin" (without the quotation marks).
Save the shell script in "bin" as a text file with unix line-breaks.

sudo chflags -R nouchg ~/.Trash/*
sudo rm -R ~/.Trash

I called my shell script "trash". After saving it open the terminal
and enter the following to turn "trash" into a command:

chmod +x ~/bin/trash

Now whenever you run up against "Insufficient privileges", simply
open up the terminal and type your command:


You will be asked for your password, and then the power of unix in
Mac OS X will now work for you, instead of against you!

Note: you need to be a user with Administrative privileges on your
Mac (as is the first User created during installation). If you are
trying to delete files on a volume other than your startup volume,
you need to modify the shell script by adding the following lines:

sudo chflags -R nouchg /volume_name/.Trashes
sudo rm -R /volume_name/.Trashes
I have setup the shell script just like the instructions said, but when I tried the "trash" command, it just said "command not found" did I miss something here? ( I am the adminstrator of the iBook)

actually no, I am fairly new to unix operating system. I heard that linux/unix is more superior that Microsoft Windows. I am a longtime mac user, so it was a easy choice for me to stick with Mac OS X.

thanks for the help...(I am doing c++ in terminal...so far it is a pain in the arse)
Keeps saying Can't find directory .trash.


It sees the command (lists rm etc on the terminal window) but does nothing. ONE time at asked me for my PW but then still said can't find dir (even after using rehash and quiting Terminal too).
Hey Gadget,
you do have something in the trash can dont you.

if the trash is already empty you will see that error you keep seeing. Put a empty folder in there and run your command.:D
Originally posted by testuser
If GadgetLover doesn't mind me quoting him from the other thread:
"Yes! Works great!! Thanks!"

There is also a cosmetic glitch; it takes the Dock a while to update its cache and show an empty Trash can after running one of these scripts. I find that clicking on the Trash, and then closing the window, twice in a row will update the display and show an empty Trash can.

I'm flattered! ;)

And, yes, I noticed the glitch too ('tis a small price to pay).
I'm so proud of myself for making a script -- and it worked! I've had things hanging in the trash for a while (privilege casualties and all). I might have to try some other ones now. Is there a good place to learn about scripts, shells, etc? I've glanced at Apple's applescript site but would like more of a tutorial thing. Thanks for the help!
Originally posted by snowgurl
Is there a good place to learn about scripts, shells, etc? I've glanced at Apple's applescript site but would like more of a tutorial thing. Thanks for the help!

Thanks. I think I will buy a book. I've been doing stuff in the Terminal so I kind of get that whole thing. I just know a little about programming but never made a good effort to learn it -- I took Pascal in college 20 years ago, does that count? I'll go check out the campus bookstore. Thanks again.
OK, I know there's a lot of ways to do this, but I found this safest whenever I help my pals over the phone... tired of doing it again and again, I made a short movie, see here
A while ago, I posted on my website a GUI way to remove stubborn items from the trash. To do this, get BATCHmod. It is freeware.

A screenshot of BATCHmod at work:
One footnote here related to emptying the trash of stubborn items. I get around pretty good in the terminal and one time I had some stubborn items in my trash that would not delete. The usual method I used was to sudo rm -R and drag and drop all the stubborn items from the trash into the terminal window to append the filenames to the command. Worked great hundreds of times before - but on this occasion something went HORRIBLY wrong!!!! I received a notice in the terminal about "are you sure you want to override..." thinking that was the standard "Are you sure" prompt I simply hit yes... and away it went...trash can was completely emptied out...all was well....so I thought. Then I started noticing some oddities....simple things. Did some investigating and within minutes I realized I had completely wiped out my user directory - the directory was still there and all the folders were still there - but nary a doc file existed. Completely and irrevocably obliterated!!!! Nothing - and I mean NOTHING will recover data from that action!

I am not sure exactly what happened but I did a little research and found some others that had the same thing happen. Seems to be a bug in the OS that causes this to happen if one of the file names being deleted has illegal characters, etc in it. I'm not sure - but I believe this was also the culprit of the infamous "iTunes wipe out your data" installer.

Anyway - just be wary of those "override" prompts in the terminal when deleting trash items.

I would be very interested in hearing from any one else more knowledgable of this subject - especially some details so that I can avoid it happening again.
It happened about a month ago - after trying every known rescue to man (short of sending it to drive savers to the tune of $800) I finally gave up and wrote it off as a lesson learned the hard way. As I said I really don't know EXACTLY what transpired so I wish someone could explain it - I do believe it has to do with illegal characters in filenames - notably slashes I bet.
FANTASTIC TESTUSER!!!! Thank you very much!!! I can't tell you how many places I have posted for a decent explanation of what happened - your's is the first realistic and understandable one. It all makes complete since now after your explaination.

Matter of fact - I am almost positive I used the wild card * in the command. Seeing as how I remember the trash having about 200 items in it. I guess I was getting a little UNIX-cocky for my own good....ooooo.....wow......using teh wildcard...big man! Hahahaha

Thx again for your great explaination!
This thread has been really helpful. Someone in my office ran into this issue and it caused a lot of problems. Going into the terminal helped him dump 4GB from the trash.

But why should this happen at all? It's a really serious problem if a user has to use the terminal and scripts to empty the trash.

just 2¢
Originally posted by bunski71
But why should this happen at all? It's a really serious problem if a user has to use the terminal and scripts to empty the trash.

just 2¢

In my previous post I explained a GUI way to empty the trash of stubborn items (BATCHmod). Why should you have to use the Terminal?:confused:
But I agree that you shouldn't use a separate program to empty the trash of stubborn items. I think OS X should have that functionality.
yes, BATCHmod is a great work around, much better than the terminal solution we used originally.....now when will Apple realize that we need to empty to the trash ; )

As I put down Apple for such a glaring oversight even one year after the release of X, I must applaud the Mac and Unix community for coming together and creating so many solutions to X problems so quickly. For almomst every issue in X, someone finds a workaround, creates a script, or writes an app to help the rest of us. FruitMenu and BATCHmod are great examples.