Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Trash Files Automatically

I have a nasty habit of downloading things, or saving files to my destkop, which are only temporary and don't need to be kept.

To stop my desktop and downloads folder becoming ever more polluted over time, I have the items automatically moved to trash every day, and upon every reboot. To do this, I opened my crontab file with:

crontab -e

... and added the following lines:

Ubuntu Mate 18.04 And Xubuntu 20.04

@daily gio trash /home/stuart/Downloads/*
@reboot gio trash /home/stuart/Downloads/*
@daily gio trash /home/stuart/Desktop/*
@reboot gio trash /home/stuart/Desktop/*

Ubuntu 16.04

@daily gvfs-trash /home/stuart/Downloads/*
@reboot gvfs-trash /home/stuart/Downloads/*
@daily gvfs-trash /home/stuart/Desktop/*
@reboot gvfs-trash /home/stuart/Desktop/*

By using the gio trash or gvfs-trash command instead of running rm -rf, I know that if there was something that I actually needed, I can dig through my trash and restore it. Now I just need to remember to clear out my trash every now and then.


Last updated: 22nd October 2023
First published: 19th May 2019