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.

References

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

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch