Alex Bepple

Notes &

Automatically emptying trash on Ubuntu

The most common mechanism for automating tasks on Ubuntu is the cron daemon. You can schedule tasks with crontab -e or you can make your life easier by using Scheduled Tasks, a graphical frontend for crontab. You might need to install gnome-schedule for that.

Now, how do we actually empty the trash? The most commonly recommended way is rm -r ~/.local/share/Trash/files/*. This, however, leaves some garbage in ~/.local/share/Trash/info, where Ubuntu keeps metadata about the contents of the Trash, including the original location and the deletion date. Merely deleting the contents of Trash/files will leave you with orphaned metadata.

A better way is to use the utilities from the trash-cli package:

trash
list-trash
restore-trash
empty-trash

The best bit is that you can provide empty-trash with a parameter. So

empty-trash 5

will permanently delete all files that have been in the Trash for more than 5 days.

Filed under ubuntu