Want a free year on Tuts+ (worth $180)? Start an InMotion Hosting plan for $3.49/mo.
Just about everybody has tried, at one time or another, to empty their OS X Trash and received an alert that the Trash couldn’t be emptied, usually for an opaque reason that's not well explained. This can be incredibly frustrating, especially if I'm not sure why it’s happening. Even if I identify the problem, it’s not always easy or even possible to fix without a lot of effort.
In this tutorial, I’ll look at several ways to force the Trash to empty using the command line in Terminal. For users who are not comfortable doing that, though, I’ll also use a dead simple app that will get rid of any problem files or folders in the Trash. When we're done, you'll be able to tackle any problem the OS X Trash throws your way.
What You'll Need
- Trash It! (NoName ScriptWare, Free)
While most of this tutorial deals with Terminal commands to solve Trash problems, Trash It! is a nice app for getting the same job done without using the command line. If you're not comfortable in Terminal or just don't want to go to the trouble of entering the individual commands, Trash It! may be your solution, and we'll briefly walk through it at the end.
Unlock Trash Files
Most of us have tried to empty our Trash, only to be brought up short by a file that’s locked or in use. The first Terminal command to try makes the Trash files editable, hopefully freeing them up to be deleted.
I'll open Terminal, and get into the Trash directory by entering the following:
Once in the Trash, I'll paste the following into Terminal and hit ENTER:
chflags -R nouchg *
Now I'll try to empty the Trash from either the Dock or the Finder menu (Finder > Empty Trash).
Remove All Trash Files in Terminal
If that didn’t work, we’re going to need to try a little harder. Again, change the directory to Trash using the
cd command in Terminal from above. Then delete everything in Trash using this command:
rm -rf *
I’ll want to be absolutely sure I'm in my Trash directory for that command, because it’s going to burn the fields and salt the earth, taking all of my files with it. I don’t want to do that in a directory that contains personal files or system files.
rm -rf is serious business and cause major problems if used improperly. You should only ever use it if you know what they're doing and feel comfortable deleting the files in the crosshairs.
To make sure I'm in the right directory before plunging ahead, I'll use the
ls command. This will list everything in the current directory; I can match the file list against what’s in my Trash.
Tip: I can also get a complete file listing using the
echo * command, but the output list doesn’t look as nice and isn’t as easily navigable as
If I don’t want to worry about all of that changing directories business and want to tell Terminal what directory to look into in the same command as I remove the files, this is a good one:
rm -rf ~/.Trash/*
Remove Just a Single File
It may only be a single file holding things up. If I can identify the troublemaker, I don’t have to delete everything in the Trash directory using the command line, just the file causing problems. From the Trash directory in Terminal, I'll use the following command to remove a single file, substituting the name of my file for the “FILE.DOC” placeholder.
Tip: Once I’ve identified the file jamming up Trash, I'll type
rm into Terminal, but don’t hit ENTER yet. Then I'll drag the file into the Terminal window to get the filepath. Hitting ENTER now will delete the file completely. I don’t even need to use the
cd command to get into the Trash directory first!
Use a Third-Party App
Using Terminal commands can be scary. If you’re not used to working with the command line, you have to be careful, because if you end up in the wrong directory, you could delete a lot of good files that you really need.
For users who aren’t comfortable taking Trash deletion into their own hands with Terminal commands, the safety of a third-party application may be what’s called for. Trash It! can pretty much clear anything out.
Launch Trash It! and select one of the two deletion options, Fast or Really Stuck. The best bet for a new user is to try Fast first, but if that doesn’t work, move on to Really Stuck.
Trash It asks for password authentication to move forward. It may take Trash It! a few moments depending on how large of a job it’s facing, so be patient.
We tried out a handful of Terminal commands and even a third-party app that should do the trick if the OS X Trash seems really stuck. Hopefully next time you run into this common annoyance, you’ll be better prepared to deal with it.
Always make sure you’re 100% comfortable deleting the files in your Trash before you move forward with any of these methods. It could be that a file is held up because it really is still in use and you don’t want to lose it or that you’ve accidentally chucked into the Trash a pile of system files necessary for OS X to function. You’ll want to be aware of what you’re deleting and know in advance that you won’t be able to recover anything removed using these methods.
Do you have another favorite app for getting rid of sticky Trash files or know of other Terminal commands to remove or identify difficult to delete files? Let us know in the comments!