Are you losing GB of storage space because you forget to empty your recycle bin? With AutoTrash, you can tell Ubuntu to automatically empty the Trash by itself, based on the conditions you specify.
You will no longer find AutoTrash in the repositories of many distributions. For most users, the easiest way to install it is to use an unofficial version of snap, available in the snap store.
If you are using Ubuntu, which in its latest versions already supports snaps by default, you can find the program in Software Center by searching for “autotrash”.
Select the “autotrash-unofficial” entry that will appear and install it by clicking on the green Install button.
For those who prefer typing commands rather than clicking, you can do the same by activating your preferred terminal and using:
If the program is not available in your distribution’s repositories but you also have a loathing for snaps, there is a workaround. Since this is a Python script, you can use pip to install autotrash with:
When you install it like this, for ease of use, be sure to include its location in your PATH variable.
Define an alias
If you installed AutoTrash via the easier way of snap, you can try it out by typing
autotrash-unofficial in a terminal. You can also set up an alias for easier access.
If you prefer to type
autotrash instead of
autotrash-unofficial to run the tool, enter the following into the terminal:
Clean your trash
AutoTrash comes with a list of settings that allow you to customize how it will clear your Trash.
-d, you can set a date threshold. Anything that has been placed in the trash within the specified number of days will remain intact; AutoTrash will erase anything older. For example, to eliminate all files older than 10 days, use:
If you have enough free space, there is no point in trying to free up even more by deleting old files. Instead of checking it yourself, you can specify a free space threshold with
--max-free. Values are in megabytes.
If you want AutoTrash to wipe out anything older than ten days only if your free space has dropped below 4 GB, you would use:
Since 1 GB = 1024 MB, the above number translates to 4 GB (4 x 1024).
You can make AutoTrash make sure you always have at least 512 megabytes of free space available with:
You can change 512 to whatever value you prefer.
It is best to always make sure that the results of any action match your original intention. You can ask AutoTrash to perform a test that does not make any real changes to your data, using the
--dry-run switch. It has no additional value. Include it as is at the end of your order to verify its result. So with this addition, the previous example would look like:
Having to run AutoTrash to manually purge the contents of your Trash is less than optimal. Fortunately, it’s easy to run it automatically. You can set up a cron job for this, but we think the following approach is even easier.
Search for “startup” among your apps and open the startup apps preferences.
Create an empty bash script the way you prefer and enter your AutoTrash command. I created a folder called
Scripts in my home directory, then an empty Bash script named
I entered my autotrash command, saved the changes (Ctrl + W), and left Nano (Ctrl + X).
With your command in your script, make it executable by entering the following into your preferred terminal:
In my case, this command looks like:
Finally, go back to the startup apps preferences. Click the Add button at the top right to create a new entry. In the window that will appear, enter a name for your entry, your script as a command, and if you wish, a comment on what it does, which will be useful for future reference.
That’s all. From now on, every time you log into your desktop, your script will be one of the first things to run, purge files from your recycle bin, and free up valuable storage.
Now that you’ve emptied your trash, if you’re still looking for more ways to clean your Ubuntu machine, check this out.
Is this article useful?