366

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

hellodear
  • 4,673
  • 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 06:53

5 Answers5

467

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.

Eliah Kagan
  • 117,780
nux
  • 38,017
  • 35
  • 118
  • 131
  • ~ always means /home/currentuser? I mean it is fixed? – hellodear May 18 '14 at 16:00
  • 22
    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
  • 13
    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
  • @Ruslan so ~ won't work on each and every system? How much specific is it? Can you please clarify? When can I say ~ is equivalent to /home/user ? Thanks. – hellodear May 20 '14 at 16:52
  • 1
    @hellodear2 see this and this questions for examples when tilde doesn't appear to work (these are about bash though). I don't really know what specific shells don't support it, but you should understand that tilde is implemented not on file system level, but on the level of application. XFE is an example of file manager which doesn't understand ~ in address bar. – Ruslan May 20 '14 at 20:27
  • 8
    why is this seemingly approx. 100 times faster than clicking trash "empty" in any file browser? – phil294 Nov 24 '16 at 13:13
  • @Blauhirn: I don't know for sure, but with rm I'd guess a single file (the trash can) gets unlinked while with the GUI maybe this is done for each file (and we can see the Trash directory is still present at home dir). If there is a lot of stuff in the trash can, it might take some time to sever all links when done one at a time. related post – Daniel Apr 19 '18 at 16:06
  • 2
    Trash directory has three directories in it.
    1. expunged
    2. files
    3. info

    Expunged is empty, files have files as shown in trash bin while info has all file names with extension .info Should I follow the above method which will remove these three directories or should I just remove from files and info directories.

    – Mobeen Jun 04 '18 at 07:11
  • 7
    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
  • One reason for rm to be faster is that real trash methods delete your trashes in all places (as above, on memory stick, another disk, ...). – simohe Aug 21 '20 at 12:50
  • that folder does not exist – KansaiRobot May 07 '21 at 15:36
  • This asks sure you want to delete the only file question would it be possible to prevent it? – alper Jan 04 '22 at 12:12
222

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

trash-empty

More interesting details about trash handling below and in the man page.

restore-trash (1)    - Restore for Command line trash utility.
trash (1)            - Command line trash utility.
trash-empty (1)      - Empty for Command line trash utility.
trash-list (1)       - List trashed files.
trash-put (1)        - Command line trash utility.
trash-rm (1)         - Removes files matching a pattern from the trash can
Pablo Bianchi
  • 15,657
jhort
  • 2,245
  • 28
    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 05:10
  • 5
    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
  • 6
    @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
  • 4
    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. – Eaten by a Grue Dec 29 '15 at 02:54
  • 1
    I find it helpful to run baobab as sudo so one can inspect all the trash bins across users and devices. I've had it happen a few times that files were in root's trash, which would not get deleted when the user emptied the trash... – CoderGuy123 Feb 08 '17 at 20:31
  • The only solution that works for me! Thanks! – Qui-Gon Jinn Sep 28 '20 at 21:43
  • trash-list returns empty even ~/.local/share/Trash/files contains files – alper Jan 04 '22 at 12:20
58

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.

Braiam
  • 67,791
  • 32
  • 179
  • 269
17

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.

Elder Geek
  • 36,023
  • 25
  • 98
  • 183
1

Please note, ~/.local/share/Trash/* might not be the only location that stores the trashed files, so removing that path is not enough if you have other partitions that also have a trash folder.

If you want to empty the trash in all available partitions, you can use the following command to empty the trash:

gio trash --empty

gio is provided by glib2, which is used by most GTK-based applications, and the gio binary should be available out-of-the-box in most of the cases if you are using a desktop environment. If not, you can install it via:

apt-get install libglib2.0-bin
Gary Wang
  • 133