Is there a way to empty the trash/wastebasket from the command line?

5,811

Solution 1

At least in Debian and Ubuntu, you can install the trash-cli package. This provides a number of commands for working with FreeDesktop.org Trash Specification compliant trash cans, like GNOME's.

/usr/bin/trash
/usr/bin/list-trash
/usr/bin/restore-trash
/usr/bin/empty-trash

To remove all trashed files, use emtpy-trash. It can also just remove files that have been in the trash more than a certain number of days. Use empty-trash x, where "x" represents the number of days.

I personally have set up a cron job that runs daily to get rid of trash over a week old.

Solution 2

There is no such thing like a system trash in Linux, but its common for many desktop environments to use ~/.Trash as trash folder. This depends on the window manager you are using.

For Gnome you can empty this folder with: rm -rf ~/.Trash/*

Share:
5,811

Related videos on Youtube

Matthew
Author by

Matthew

Updated on September 17, 2022

Comments

  • Matthew
    Matthew over 1 year

    This would be great especially considering the latest version of Ubuntu is very slow when displaying directories on my PC...

  • Michael Mrozek
    Michael Mrozek over 13 years
    I suspect the window manager has little to do with what folder is used for trash storage, but I know what you meant :)
  • Steven D
    Steven D over 13 years
    On my gnome system the trash is found in ~/.local/share/Trash.
  • amarillion
    amarillion over 13 years
    That is only true if all your stuff is on one partition. Every drive/partition has its own trash (wouldn't make sense to move a multiple GB file over to a different drive to store it in the trash)
  • Cole
    Cole over 13 years
    Oh, I wasn't aware of multiple partitions :-) @Steven D: what gnome version are you using? maybe this has changed or is partly distribution specific...
  • livibetter
    livibetter over 13 years
    I wonder if this trash-spec would help creating a more generic solution?
  • Steven D
    Steven D over 13 years
    @echox I checked it on GNOME 2.32 distributed by Ubuntu.
  • Matthew
    Matthew over 13 years
    @tante that's the sort of answer I was after, yes
  • Matthew
    Matthew over 13 years
    that's a great answer.
  • Matthew
    Matthew over 13 years
    @echox nice logo. hail to the thief.