Home Empty Trash How to automatically empty your trash in Ubuntu with AutoTrash

How to automatically empty your trash in Ubuntu with AutoTrash

by David
How to automatically empty your trash in Ubuntu with AutoTrash

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.

Installing AutoTrash

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”.

Keep Ubuntu clean with Autotrash Locate Snap

Select the “autotrash-unofficial” entry that will appear and install it by clicking on the green Install button.

Keep Ubuntu Clean with Autotrash Install SnapKeep Ubuntu Clean with Autotrash Install Snap

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.

Keep Ubuntu clean with the installation of Pip AutotrashKeep Ubuntu clean with the installation of Pip Autotrash

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:

Keep Ubuntu clean with the Snap Autotrash aliasKeep Ubuntu clean with the Snap Autotrash alias

Clean your trash

AutoTrash comes with a list of settings that allow you to customize how it will clear your Trash.

READ:   Elive Review: for discerning Linux users

Using -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).

Keep Ubuntu clean with free Autotrash MaxKeep Ubuntu clean with free Autotrash Max

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:

Keep Ubuntu clean with Autotrash Min Keep FreeKeep Ubuntu clean with Autotrash Min Keep Free

Automatic purge

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.

READ:   4 useful extensions to make GNOME Desktop easier to use

Search for “startup” among your apps and open the startup apps preferences.

Keep Ubuntu Clean with Autotrash Starter App PreferencesKeep Ubuntu Clean with Autotrash Starter App 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 autoautotrash.sh inside.

Keep Ubuntu clean with Autotrash Create ScriptKeep Ubuntu clean with Autotrash Create Script

I entered my autotrash command, saved the changes (Ctrl + W), and left Nano (Ctrl + X).

Keep Ubuntu clean with the Autotrash Enter commandKeep Ubuntu clean with the Autotrash Enter command

With your command in your script, make it executable by entering the following into your preferred terminal:

In my case, this command looks like:

Keep Ubuntu Clean with Autotrash Make Script ExecutableKeep Ubuntu Clean with Autotrash Make Script Executable

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.

Keep Ubuntu clean with Autotrash Add script on startupKeep Ubuntu clean with Autotrash Add script on startup

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.

Keep Ubuntu Clean With Autotrash Script As Starter ApplicationKeep Ubuntu Clean With Autotrash Script As Starter Application

Now that you’ve emptied your trash, if you’re still looking for more ways to clean your Ubuntu machine, check this out.

Related:

Is this article useful?

!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version=’2.0′;
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,’script’,
‘https://connect.facebook.net/en_US/fbevents.js’);
fbq(‘init’, ‘400239050508508’);
fbq(‘track’, ‘PageView’);

You may also like

Leave a Comment