Linux timing automatic deletion of old junk files Autotrash tool

  • 2020-11-26 19:06:45
  • OfStack

Autotrash is a command-line program that automatically cleans up old deleted files. It clears files in the recycle bin for more than a specified number of days. You do not need to empty the recycle bin or perform SHIFT+DELETE to permanently clear files/folders. Autortrash processes the contents in the recycle bin and automatically deletes them after a certain period of time. In short, Autotrash will never let your trash get too big.

Install Autotrash

Autotrash exists by default in repositories based on Debian systems. To install autotrash on Debian, Ubuntu, Linux Mint, run:

$ sudo apt-get install autotrash

On the Fedora:

$ sudo dnf install autotrash

For Arch linux and its variants, you can install it using any AUR helper program, such as Yay.

$ yay -S autotrash-git

Automatically cleans up old junk files

Every time you run autotrash, it will scan your ~ /. local/share/Trash/info directory and read. trashinfo to find them and delete date. Files are deleted if they have exceeded the specified date in the recycle bin.

Let me give you a few examples

To delete files that have been in the recycle bin for more than 30 days, run:

$ autotrash -d 30

As shown in the example above, Autotrash automatically removes files from the recycle bin if they are more than 30 days old. You don't have to delete them manually. Just drop your useless files in the recycle bin and forget. Autotrash will process deleted files.

The above command only deals with the garbage directory of the currently logged in user. If you want autotrash to handle all users' garbage directories (not just in your home directory), use the -ES62en option, as shown below

$ autotrash -td 30

Autotrash also allows you to delete files based on the amount of recycle bin or disk space available.

For example, look at the following example:

$ autotrash --max-free 1024 -d 30

According to the command above, if the remaining space in the recycle bin is less than 1GB, autotrash will clear deleted files from the recycle bin that have been over 30 days. This can be useful if you don't have enough space in your recycle bin.

We can also remove files from the recycle bin at the earliest possible time until the recycle bin has at least 1GB space.

$ autotrash --min-free 1024

In this case, there are no restrictions on old deleted files.

You can combine these two options (-- ES88en-ES89en and -- max-ES91en) in one command, as shown below

$ autotrash --max-free 2048 --min-free 1024 -d 30

According to the command above, if the free space is less than 2GB, autotrash will read the recycle bin and then focus on capacity. At this point, delete files that are more than 30 days old, or if less than 1GB is available, delete the updated files.

As you can see, all commands should be run manually by the user. You may be wondering, how do I automate this task? It's easy! Simply add autotrash as the crontab task. The command will now run automatically at the scheduled time and clear the files in the recycle bin according to the defined options.

To add these commands to crontab, run:

$ crontab -e

Add tasks, such as:

@daily /usr/bin/autotrash -d 30

autotrash will now clear files in the recycle bin for more than 30 days per day.

Please note that if you accidentally delete any important files, they will disappear permanently after the date specified, so be careful.

See the man page for more information on Autotrash.

$ sudo dnf install autotrash0

It's not a big deal to empty the recycle bin or press SHIFT+DELETE to permanently delete anything unused from the Linux system. It only takes a few seconds. However, if you need additional programs to handle junk files, Autotrash may be helpful. Try 1 and see how it works.

conclusion


Related articles: