When we delete a file or folder from our system, they are moved to the trash (Linux) or trash (Windows). Again and again, we have to get rid of these mostly useless files and folders that are on our system in order to free up space for other important data. If you want your Debian to automatically take care of the system bin for a certain period of time, you can use the Autotrash command-line utility.
Autotrash is a utility that looks for information about its contents in the basket folder on FreeDesktop.org, and then deletes part of the basket depending on the parameters you specify.
This article explains how to install the Autotrash utility, find help, and use it. We will explain the procedure with some examples that will help you understand the widely used functions of this utility.
We ran the commands and procedures mentioned in this article on the Debian 10 Buster system.
Install Autotrash via Debian Terminal
We will install the Autotrash CLI through the Terminal application. You can launch the Terminal through a search in the Application Launcher as follows:
Please note that only an authorized user (root or sudo) can add / update, delete and configure software on a Debian system.
Step 1. Update the repository index of your system.
To install the latest software available in Debian online repositories, your system repository index must be up to date.
Run the following command as sudo to update your local system repository index to the Internet index.
$ sudo apt-get update
The system may ask you to enter a password for sudo. Enter the password and your storage index will be updated.
Step 2: Install Autotrash CLI
Now you can install the autotrash utility by running the following command as sudo in your terminal application:
$ sudo apt-get install autotrash
The system may ask you for the Y / n option before starting the installation procedure. Please enter Y to continue.
Step 3: Verify Autotrash Installation (Optional)
You can check the version number of the installed Autotrash software, and also check whether it is actually installed on your system. To do this, run the following command:
$ autotrash --version
$ autotrash -V
The results ensure that autotrash version 0.1.5 is installed on my Debian.
Using Autotrash CLI (with examples)
Help Autotrash will tell you everything you can do with this application. You can view the help as follows:
$ autotrash --help
For more information, you can view the autotrash man page with the following command:
$ man autotrash
Now we will introduce some Examples this will detail how you can best use this utility:
Example 1: Delete files older than x days
This is the most widely used Autotrash feature. You can use the following command syntax to automatically delete files in your system bin within x days:
$ autotrash -d [days]
For example, the following command will delete files that have completed their 30 days from the trash.
$ autotrash -d 30
This gives you enough time to recover any files you may wish for within 30 days.
The following use of the command allows you to apply this function not only to your deleted files, but also to the deleted files of all users using the system:
$ autotrash -td [days]
$ autotrash -td 30
Example 2: Removing Files Based on Free Space Left
You can use automatic cleaning to clean files only if the storage has less than megabytes of free space. For example, if you set the value to 1024, the automatic garbage removal feature will only start working if there is less than 1 GB of free space in the trash. Until this time, the automatic basket will exit normally without scanning the basket directory.
$ autotrash --max-free 1024 -d 30
Similarly, you can use autotrash to provide a minimum of M megabytes of free space.
$ autotrash --min-free 1024
You can even combine the two teams to make sure that the automatic basket starts reading the basket if it has less than 2 GB of free space, and then perform a check. Then the team will delete files older than 30 days, and also delete additional files so that 1 GB of space is always available.
$ autotrash --max-free 2048 --min-free 1024 -d 30
Example 3: Delete M the number of megabytes
You can use the utility to clean at least M megabytes by first deleting the oldest garbage addition. This feature uses recycle bin entries rather than individual files. This means that if your oldest recycle bin item is 1 GB in size and you are requesting a deletion of at least 10 MB (M = 10), an automatic recycle bin will delete 1 GB.
$ autotrash --delete M
$ autotrash --delete 1024
The examples we presented will help you set up even more customizable ways to empty the trash. Now you do not need to worry about running out of space on your system due to system junk. The autotrash utility will automatically take care of deleting unnecessary files based on your criteria.
Automatically empty recycle bin in Debian via Autotrash CLI