How can I empty the trash from the Terminal?


Another solution would be to create AppleScript containing the folowing code

tell application "Finder"
    empty the trash
end tell

save it as emptytrash for example and execute it via open emptytrash.app

or even better (as suggested by Chris) - execute:

osascript -e 'tell app "Finder" to empty'

Since trash is a Finder thing, this should be more compatible in the long run.

| improve this answer | |
  • 6
    Directly from the command line: osascript -e 'tell app "Finder" to empty' (though you may want to put in a shell script to avoid having to get the syntax exactly right each time). – Chris Johnsen Mar 25 '11 at 5:56

Trash is actually a hidden folder in the user's folder named .Trash

If you delete it's contents, you empty the trash. You can use

rm -rf ~/.Trash/*

Just be careful with it so you don't delete something else ;)

| improve this answer | |
  • 8
    But this will not delete .Trash on mounted media/network volumes. – mspasov Mar 24 '11 at 16:04
  • @mspasov, in many cases that is a feature, not a bug. In any case it also answers, "How can I empty just my local trash without unmounting my external volumes?" ;) – Wildcard Sep 26 '16 at 10:03

A review of various command line tools, for managing the Trash from command line:


| improve this answer | |

If you have Homebrew installed, you can easily install trash by typing:

brew install trash

Then, to empty the trash, you only have to type the following from the command line:

trash -e

It's a pretty little piece of software.

$ trash
usage: trash [-ulesv] <file> [<file> ...]

  Move files/folders to the trash.

  Options to use with <file>:

  -a  Use system API for trashing files instead of asking
      Finder to do it. (Faster, but the 'put back' feature
      in the Finder trash will not work if files are trashed
      using this method.) Finder is still used for trashing
      files you have no access rights for.
  -v  Be verbose (show files as they are trashed, or if
      used with the -l option, show additional information
      about the trash contents)

  Stand-alone options (to use without <file>):

  -u  Check for updates (and optionally auto-update self)
  -l  List items currently in the trash (add the -v option
      to see additional information)
  -e  Empty the trash (asks for confirmation)
  -s  Securely empty the trash (asks for confirmation)

  Options supported by `rm` are silently accepted.

Version 0.8.5
Copyright (c) 2010 Ali Rantakari, http://hasseg.org/trash
| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .