As on Windows, deleting a file on Linux doesn’t actually delete it: it moves it to the Trash, Garbage, Rubbish Bin, Waste Basket — the exact term varies. This is all very well as if you delete something by accident, or deliberately and regret it, you can get it back. However, unlike on Windows, the Linux Trash is never emptied. In these days of massive hard disks wasted space isn’t so much of a problem but when you do wish to retrieve something the folder takes longer to open and it’s more difficult to find what you seek.
There is a package called trash-cli
that includes a program that will remove stuff that has been there for longer than a given number of days. After installing trash-cli
you run it from a terminal by typing:--
trash-empty 7
This will get rid of stuff more than a week old.
All very nice but you still have to keep doing it manually and it would be better if it was done automatically everyday. One way of doing this is using anacron.
Make a file as root in /etc/cron.daily
called cleartrash
. I’ll use the common nano text editor in this example but you can use whatever you prefer. Type:--
sudo nano /etc/cron.daily/cleartrash
And then paste or type this into the empty file:--
#!/bin/sh
exec sudo -H -u USERNAME /usr/bin/trash-empty 7
Change USERNAME
to whatever yours is. All anacron tasks are run as root and without that it’ll empty root’s Trash rather than yours.
Save and close the editor, that’s Ctrl-o Ctrl-x on nano, and then type:--
sudo chmod 0755 /etc/cron.daily/cleartrash