277

I am not able to search trash anywhere. Can you please tell me a command or anything like that to empty the trash using terminal ?

  • 2
    This was posted 3 years ago. We need something that spells this out including what version it works for here in 2017 – SDsolar Jul 29 '17 at 6:53
363

You can use the rm command:

rm -rf ~/.local/share/Trash/*

The rm command removes (deletes) files or directories.

-f, --force     Ignore nonexistant files, and never prompt before removing.
-r, -R, --recursive     Remove directories and their contents recursively.

The trash folder is found at: $HOME/.local/share/Trash

Be careful how you use the rm command - the files aren't sent to a trash can where you can undelete them, so it's not easy to undo.

| improve this answer | |
  • 13
    This wont work if the trash is somewhere else. – Braiam May 18 '14 at 17:56
  • 1
    @hellodear2 Notice that ~ is only a shell-specific thing, which expands to your home directory path. Using, e.g. "~/some/path" won't expand because of quoting. Likewise, not all file managers will understand ~ if you enter it in address bar. – Ruslan May 19 '14 at 10:05
  • 11
    Sensitive system folders and files cannot be removed without privileges, and rm cannot remove folders at all, unless you give it the -r (or equivalent) option. However using rm without proper care may case loss of lost of important personal files, especially if used with wildcard arguments. – Marc van Leeuwen May 19 '14 at 19:06
  • 6
    why is this seemingly approx. 100 times faster than clicking trash "empty" in any file browser? – phil294 Nov 24 '16 at 13:13
  • 3
    Deleting this broke my trash bin: after doing it, I couldn't send files to trash anymore (couldn't write to ~/.local/share/Trash/info/*.trashinfo) – 7hibault Jul 20 '18 at 14:11
147

After you sudo apt-get install trash-cli, you can do

trash-empty

More interesting details about trash handling in the man page.

| improve this answer | |
  • 22
    This is the correct answer. If you have an USB stick in, for example, the files you trash in it will be put in an hidden directory in the root of the device (at least it happened last time I checked) .Trash-$UID - so in this case the trash is physically in two different places... – Rmano May 19 '14 at 5:10
  • 2
    So sad that you have to install a package just to empty the trash. Counting the trash against the disk space is one of the most annoying features of Ubuntu. – Michael May 15 '15 at 21:48
  • 4
    @Michael "Trash" is a feature provided by the desktop manager, which is a layer above the stuff that you would usually use in the command line. Really all it does is move files into a hidden folder on the same device, and store some metadata so they can be put back into place if the user would like. You don't actually reclaim any space until you "empty" the trash, which is when the file is actually deleted. – Seamus Connor Aug 24 '15 at 20:50
  • 3
    It should be noted that this command is user specific. I installed it and was scratching my head about why it wasn't working til I realized the files were in the trash of another user. – billynoah Dec 29 '15 at 2:54
  • For OS X, trash -e. (PS: brew install trash to install the trash) – SparkAndShine Sep 2 '16 at 17:16
57

You are looking for the $XDG_DATA_HOME/Trash directory. The trash directory is defined in the "Desktop Trash Can Specification" of the freedesktop site. This variable is normally not available in the terminal windows, hence you will need for trash-empty. This command follows all the specification of the Freedesktop.org and it's intelligent enough to find out where the Trash is. You will need to install it first.

There are other tools for this, like gvfs-trash --empty which can also send items to the Trash can.

| improve this answer | |
  • +1 for $XDG_DATA_HOME. How did you get that? – jobin May 18 '14 at 18:08
  • 4
    @Jobin is all in the specification. ramendik.ru/docs/trashspec.html – Braiam May 18 '14 at 18:10
  • @Braiam Can you please elaborate more? How can I use it? I am not getting how it is solving my purpose. Please explain a little bit. And I don't want to trash the items, I want to empty the trash. – hellodear May 20 '14 at 16:54
  • 2
    @hellodear2 trash-empty empties the trash. You only need to run it. The binary is in the trash-cli package. Is the same as jhort solution just that I explain where it comes from and offer another tool. – Braiam May 20 '14 at 18:07
  • 2
    Now gio trash --empty, at least on Ubuntu 18.10/Gnome 3. – J. B. Rainsberger Feb 14 '19 at 14:30
11

With trash-cli installed type trash-empty I've used this successfully to empty the trash across different drives and numerous locations.

to install trash-cli type sudo apt-get install trash-cli

Or you could use this script to do it for you.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.