In this post, we will explain how to install the Autotrash utility to automatically empty the trash in Ubuntu. This way you can get rid of old and useless files and make room for important files.
Note: The commands discussed here have been tested on Ubuntu 20.04 LTS (Focal Fossa). You must have be root user or have sudo privileges to install Autotrash on your Linux system.
Installing Autotrash
Autotrash utility is by default not installed in the Ubuntu OS. However, it is available as a snap package that can be easily installed using the snapd.
Step 1: Install Snapd
First, install snapd on your system. Execute the below command to do so:
$ sudo apt install snapdEnter sudo password, after that the installation of snapd will be started on your system. Once snapd is installed, you can use it to install Autotrash snap.
Step 2: Install Autotrash
Execute the below command in Terminal to install Autotrash utility on your system:
$ sudo snap install autotrash-unofficialOnce the Autotrash is installed you will see the below output:
Step 3: Create an alias for Autotrash
After installation of Autotrash via snap, you will have to run every command by typing the complete snap name that is autotrash-unofficial. You can just use autotrash instead of complete snap name autotrash-unofficial by creating an alias as follows:
$ sudo snap alias autotrash-unofficial autotrashThe alias will support calling the autotrash-unofficial as just autotrash.
Note: In case, you want to remove the alias, execute the below command:
$ sudo snap unalias autotrashTo verify if the Autotrash has been successfully installed and to view its version, execute the below command in Terminal:
$ autotrash -V
Using Autotrash to Automatically Empty the Trash in Ubuntu
Autotrash allows you to automatically empty the trash based on certain options that you need to specify. It can automatically delete files based on age, size, and free space on the trash location.
Automatically Deleting Files older than x number of days
This is the most commonly used Autotrash functionality. The following command syntax can be used to automatically delete the files that exist in the trash for more than x number of days:
$ autotrash -d [number of days]This will automatically delete the files that have been in the trash over the period you specified. For instance, the below command will delete the files that have been in the trash for more than 45 days:
$ autotrash -d 45If you want to restore any deleted file, you can do that within 45 days.
Automatically Deleting files based on free-space left
Using the Autotrash utility, you can make sure a specific amount of disk space is free in the Trash location. Here is the syntax of the command:
$ autotrash --min-free [free-space in MB]For instance, the below command will make sure there is a minimum of 512 MB of free space:
$ autotrash --min-free 512Automatically Deleting M number of megabytes
Using Autotrash -delete option, you can allow it to automatically delete at least M megabytes, removing the oldest trashed items first. Here is the syntax of the command:
$ autotrash --delete [data size in megabytes]This option removes the trashed entries, not the individual files. To explain it, consider you have an older trashed directory of 1 GB. If you request Autotrash to delete 512 MB (M=512), it will remove 1 GB.
$ autotrash --delete 512Uninstalling Autotrash
In case you no longer need Autotrash on your system, you can easily remove it using the following command in Terminal:
$ sudo snap remove autotrash-unofficialEnter password for sudo, after which Autotrash will be removed from your system.
In this post, we have explained how to install Autotrash on Ubuntu system. Now the Autotrash will automatically delete the files residing in the Trash based on the conditions you specified.