Empty Trash via Script in El Cap and newer?

duffcalifornia
Contributor

I know you used to be able to run a simple rm -r (user)/.Trash command to empty the trash, but that doesn't seem to be the case in El Capitan and newer - you're supposed to drag all the files in the Trash to the terminal window and then run the command.

Is there some way to automate that process so I could include it in a general first aid Self Service policy?

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

It should work if you do:

rm -R /Users/username/.Trash/*

The * wildcard tells it to match any files in the user's hidden trash directory. If that doesn't work, post back. I can't imagine it won't work though.

View solution in original post

4 REPLIES 4

mm2270
Legendary Contributor III

It should work if you do:

rm -R /Users/username/.Trash/*

The * wildcard tells it to match any files in the user's hidden trash directory. If that doesn't work, post back. I can't imagine it won't work though.

duffcalifornia
Contributor

That's a bingo!

cbrewer
Valued Contributor II

@duffcalifornia I'm curious to know what the scenario is where you'd want to delete everything in a User's trash.

RobertBasil
Contributor

Does not work in El Cap or Sierra.

Some files when deleted are in the trash but are not listed in the .Trash directory or it's sub directories anymore.

For example, here is a file that i just dragged to the trash and it's location:

/Users/robertbasil/Library/Mobile Documents/com~apple~CloudDocs/.Trash/1Password-6.3.1.zip