Skip to content
Home » How to Force Empty the Trash on a Mac

How to Force Empty the Trash on a Mac

Dark terminal card headed Exit 0, files still there, showing rm -rf on a wildcard returning exit status 0 while a following ls -a still lists .hidden.txt and .hiddendir, with labels reading the asterisk never matches a leading dot and use ~/.Trash/ rather than ~/.Trash/*

Empty Trash gets most of the way through and then stops on one item, or the Trash refuses to empty at all. There are three causes worth knowing apart, because each has a different fix: something still has the file open, the item is locked, or you do not have permission to remove it. Restarting the Mac clears the first one and is why “just reboot” sometimes works — but knowing which of the three you have is faster, and it stops you reaching for a command that deletes more than you meant.

Try the built-in options first

Two things worth doing before anything more involved, because between them they resolve most cases:

  • Delete one item on its own. Open the Trash, select the stubborn file, and press Option-Command-Delete to delete immediately. This skips the all-or-nothing behaviour of Empty Trash, so one problem file no longer blocks everything else.
  • Quit the app that made the file, then restart the Mac if that fails. A restart releases every open file handle on the system, which is precisely the first of the three causes.

If the Trash empties after a restart, you had a file in use and you are done. If it still refuses, the message it gives you narrows things down, and the next two sections cover what each one means.

“The item is in use”

macOS will not remove a file that a running process still has open. The Finder tells you this without telling you which process, which is where lsof comes in — give it the path and it names the culprit:

$ lsof /path/to/busy.log
COMMAND   PID    USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
tail    98195 osxhub    3r   REG   1,15        6 43266657 /path/to/busy.log

The path and user name are redacted here; the columns are as printed. COMMAND is the program holding the file — quit that app and the file frees up. To check everything in the Trash at once, point lsof at the folder:

lsof ~/.Trash

No output means nothing is holding anything, and the cause is one of the other two. This is the same technique that identifies what is keeping a disk from ejecting, and it is worth knowing generally: “something is using it” is answerable, not a dead end.

Resist the urge to force-quit whatever appears. If it is an app you were using, quitting normally lets it write out its work first; if it is a background process you do not recognise, a restart is the safer way to clear it.

Locked items

The Locked checkbox in the Finder’s Get Info window sets a file flag called uchg, and it survives being moved to the Trash. A locked item does not produce an “in use” complaint — it fails differently, which is the tell:

$ ls -lO locked.txt
-rw-r--r--@ 1 osxhub  wheel  uchg 0 20 Jul 21:26 locked.txt
$ rm locked.txt
rm: locked.txt: Operation not permitted

Operation not permitted rather than a permissions error, on a file you own, in your own Trash. Clearing the flag takes one command, after which the file removes normally:

chflags -R nouchg ~/.Trash

-R applies it through everything in the folder, which matters because the lock may be on a file several levels down inside a folder you threw away. This only unlocks; it does not delete anything, so it is safe to run before you know which item is at fault. In the Finder the equivalent is selecting the item, pressing Command-I, and unticking Locked.

The user name in that listing is redacted; nothing else is changed. uchg sits in the same flags column as hidden, the flag that keeps files out of the Finder — two different attributes, shown the same way. ls -lO is worth remembering generally: when a file is behaving oddly and permissions look fine, that column is usually the reason.

Emptying from the Terminal

The Trash is an ordinary folder at ~/.Trash, so the shell can empty it. Two things to be clear about before you do.

First, this is permanent in a way that emptying the Trash from the Finder is not — there is no confirmation, no progress, and nothing to put back. Second, it does not solve either of the causes above by itself: a file held open still cannot be removed, and a locked file gives you Operation not permitted exactly as the Finder does. Clear those first, then:

ls -A ~/.Trash          # look at what is there first
rm -rf ~/.Trash/         # then empty it

Run the ls first, every time. It costs a second and it is the only check between you and a mistyped path. The trailing slash on the second command is deliberate: it empties the folder’s contents rather than removing the folder, which macOS expects to exist.

If sudo seems necessary, stop. Items in your own Trash belong to you; needing root points at a locked file or a file owned by another account, and the fix is to address that rather than to escalate. sudo rm -rf aimed at the wrong path is the single most destructive command a Mac user can type.

The command that reports success and leaves files behind

The version of this command that circulates most widely ends in /* rather than a slash, and it does not do what it appears to. Here is a folder holding one ordinary file and two hidden ones:

$ ls -a
.
..
.hidden.txt
.hiddendir
normal.txt
$ rm -rf ./*
$ echo $?
0
$ ls -a
.
..
.hidden.txt
.hiddendir

Exit status 0, no error, and both hidden items still there. The shell expands * before rm ever runs, and by default it does not match names beginning with a dot — so rm -rf ~/.Trash/* deletes the visible items, reports success, and leaves everything hidden untouched. If you then check the Trash in the Finder and it looks empty, you have no reason to suspect otherwise.

This matters because deleted app support folders and dot-files are exactly the sort of thing that ends up in the Trash, and they are usually what someone is trying to clear when they reach for the Terminal in the first place. Using ~/.Trash/ with the trailing slash removes the folder’s whole contents, hidden entries included.

External drives have their own Trash

Deleting a file from an external drive does not move it to ~/.Trash. Each volume keeps its own, in a hidden folder named .Trashes at the top level of that drive, with a subfolder per user account. The file stays on the external disk, still occupying its space, until the Trash is emptied while that drive is connected.

This is the usual explanation for an external drive that will not free up space after a big deletion, and for a Trash that appears to refill when you plug a drive back in. Nothing is wrong — the Finder is showing you the contents of that volume’s own Trash, which it could not empty while the drive was absent. Connect the drive and empty the Trash normally.

Quick reference

SymptomCauseFix
One item blocks the whole TrashEmpty Trash is all-or-nothingSelect it, Option-Command-Delete
“The item is in use”A process still has it openlsof ~/.Trash, quit that app, or restart
Operation not permittedLocked (uchg flag)chflags -R nouchg ~/.Trash
Trash “empties” but space is not freedHidden items survived a * globUse ~/.Trash/, not ~/.Trash/*
External drive still fullFiles are in that volume’s .TrashesConnect the drive, then empty

In order: delete the single item immediately, restart if something has it open, unlock with chflags if you get Operation not permitted, and treat the Terminal as the last step rather than the first — it removes the same files with none of the protection.

Leave a Reply

Your email address will not be published. Required fields are marked *