Autotrash, automatically purges old files from the trash

about autotrash

In the next article we are going to take a look at Autotrash. If you are looking for a command line tool that can be used to delete old files from trash automatically and thus eliminate garbage from your distribution, this is a good option. With it, you will not have to be aware of emptying the trash in your graphical environment every time you see it full, Autotrash will do it periodically for you in a fully automated way.

All Gnu / Linux desktop environments have a trash can, and when the user clicks the 'buttonDelete', the files go there. Over time, the data fills up the trash and takes up a space that can turn out to be considerable.

Autotrash is a utility that allows purge old files that have been deleted by the user and have remained in the recycle bin for a specified number of days, which can be specified by the user. After the established period of time, the tool will start up and delete the contents of the directory from the trash. Here you have to remember that in Ubuntu the bin is usually located in ~ / .local / share / Trash / files. It is in this folder where all the deleted files that you have sent to the trash are housed.

Related article:
How to manage the trash from the terminal

Install Autotrash on Ubuntu

Autotrash is a handy way to easily configure a Gnu / Linux PC to dump the garbage. It can be configured with a Cron job and can even be used to purge the trash folders of multiple users.

To proceed with the installation, we just have to open a terminal (Ctrl + Alt + T) and write the following command in it:

autotrash installation on Ubuntu

sudo apt install autotrash

Use Autotrash

Every time Autotrash runs, this will scan the directory ~ / .local / share / Trash / info and it will read the files .trashinfo to find your deletion date. If the files have been in the trash folder longer than the defined date, they will be deleted.

For purge files that have been in the trash folder for more than 30 days, you just have to execute the command:

autotrash -d 30

Based on the example above, if the files in the Trash folder are older than 30 days, Autotrash will automatically remove them from the Trash. You do not need to remove them manually. We just have to send the unnecessary garbage to the trash and forget about it.

The above command will only process the garbage directory of the currently logged in user. In case you need perform an Autotrash to process the garbage directories of all users on a systemAll you have to do is use the -t option as shown below:

autotrash -td 30

Autotrash also allows delete files from the trash based on the remaining or available space in the trash file system. An example of this would be the following:

autotrash --max-free 1024 -d 30

Based on the above command, the autotrash will only delete files that are more than 30 days old from the trash, if there is less than 1GB of space left in the trash file system. This can be useful if the junk filesystem is running out of space.

Automate Autotrash

As we have just seen, all commands must be executed manually by the user. But if you are looking to automate this task, there will be nothing more than add Autotrash as input crontab. In this way the commands will be executed automatically at a scheduled time, which will purge the files from the trash according to the defined options.

To program this, we will have to edit the file crontab with the command:

crontab -e

For this example we are going to add the line:

autotrash crontab

@daily /usr/bin/autotrash -d 30

After saving it, now Autotrash will purge files that are in the trash folder for more than 30 days, every day.

Help

For information about this utility, you can consult the help using the command:

autotrash-help

autotrash -h

Or the man pages:

man page

man autotrash

When using this tool, keep in mind that If important files are deleted, they will disappear permanently after the defined days, so it is best to be careful not to get surprises.


Be the first to comment

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.