16

Is there any way to configure Ubuntu to permanently delete files from trash after a certain amount of time?

I don't get why that's not the default behavior in any major OS. I don't want to think about administrating my trash, but I don't want to accidentally delete something either. Am I the only one with that opinion?

  • You might want to take a look at this question - http://askubuntu.com/questions/87744/how-to-make-downloads-folder-behave-like-a-temp-directory – jokerdino Jun 01 '12 at 08:59
  • Just wanna say I fully agree with your opinion. I guess someday, it will become standard. – Balmipour Jan 20 '17 at 11:12

4 Answers4

21

Use trash-cli Install trash-cli (click image to install or run sudo apt-get install trash-cli).

Run trash-empty 30 to remove all files from trash which are older than 30 days. (You can change this number as you like.)

To automate this, add a command to Startup Applications:

enter image description here


Please note: If you use older Ubuntu versions than 12.04, the command is empty-trash!

Jakob
  • 10,579
11

If you're on GNOME, there's now a feature for that! Go to Privacy in your settings and look under Purge Trash & Temporary Files.

Purge trash

More at https://help.gnome.org/users/gnome-help/stable/privacy-purge.html.en.

Update for Ubuntu 23.10:

In Ubuntu 23.10 with GNOME 45, this is what the screen now looks like:

Screenshot of option: "Automatically Empty Rubbish Bin every 30 days"

You can configure the trash (or "Rubbish Bin" in British English) to be emptied every 30 days or another interval of your choice. It will empty the entire rubbish bin and it will not keep files that have been deleted recently. So this feature doesn't do exactly what the original question requested.

Flimm
  • 41,766
Pieter
  • 213
4

Try with Autotrash!

Autotrash is a simple Python script comes with Ubuntu 10.10 Maverick Meerkat which will purge files from your trash when they become older than a given days,purge older files to ensure a specific amount of disk space is free,etc.It uses the FreeDesktop.org Trash Info files included in the new GNOME system to find the correct files and the dates they where deleted.

Features:

  • Remove files that are older then a given number of days (autotrash -d N,where N is the number of days)
  • Purge older files to ensure a specific amount of disk space is free (autotrash --min-free=M,M is the amount of free space you want to ensure you have, in megabytes.)
  • Check for remaining disk space, and only delete if you are running out (autotrash --max-free=M,M is the amount of free space left, in megabytes.)
  • Delete regex matching files first (see –delete-frist option)

For more info,execute this in terminal:

autotrash --help

AutoTrash is already in Ubuntu 10.10′s repository,it can be installed from Ubuntu Software Center.For Ubuntu 10.04 and 9.10 user,install this from PPA:

sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install autotrash

Info: http://www.logfish.net/pr/autotrash/

Source: http://ubuntuguide.net/automatically-delete-files-older-than-n-days-from-trash-using-autotrash/

For a different approach and a more comprehensive guide: http://helpdeskgeek.com/linux-tips/automatically-empty-the-trash-in-ubuntu/

jasmines
  • 11,011
0

Ubuntu 20.04

In Ubuntu 20.04 you can go to Privacy > File History & Trash in your settings menu and set the Automatic Delete Period to a predefined value. enter image description here

If you want a custom value, you might want to use dconf to customize it. Open dconf and go to /org/gnome/desktop/privacy/old-files-age and change it to a value you like. enter image description here For example I choose 365 days

Paul
  • 142
  • This will delete the entire trash folder, and it will not keep recently deleted files. – Flimm Nov 08 '23 at 18:04
  • Hey are you sure about this? The description shown in my screenshot is not very clear. Do have some additional source? – Paul Nov 08 '23 at 18:20