Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux Autotrash tool that automatically deletes old junk files on a regular basis

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Autotrash is a command line program that automatically clears old deleted files. It clears files in the Recycle Bin for more than the specified number of days. You do not need to empty the Recycle Bin or execute SHIFT+DELETE to permanently erase files / folders. Autortrash processes the contents of the Recycle Bin and automatically deletes them after a specific period of time. In short, Autotrash will never make your garbage 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 Fedora:

$sudo dnf install autotrash

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

$yay-S autotrash-git

Automatically clean up old junk files

Whenever you run autotrash, it scans your ~ /. Local/share/Trash/info directory and reads .trashinfo to find out when they were deleted. If the files have exceeded the specified date in the Recycle Bin, they are deleted.

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, if a file in the Recycle Bin is longer than 30 days, Autotrash automatically deletes it from the Recycle Bin. You don't have to delete them manually. Just put the useless files in the Recycle Bin and forget them. Autotrash will process deleted files.

The above command only deals with the junk 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-t option, as shown below

$autotrash-td 30

Autotrash also allows you to delete deleted files based on the available capacity of the Recycle Bin or free disk space.

For example, consider the following example:

$autotrash-- max-free 1024-d 30

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

We can also clear files from the Recycle Bin at the earliest time until there is at least 1GB space in the Recycle Bin.

$autotrash-- min-free 1024

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

You can combine these two options (--min-free and-- max-free) into one command, as shown below

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

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

As you can see, all commands should be run manually by the user. You may wonder how I can automate this task? It's easy! Simply add autotrash as a crontab task. The command now runs automatically at the scheduled time and clears 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

Now, autotrash will clear files from the Recycle Bin for more than 30 days every day.

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

Refer to the man page for more information about Autotrash.

$man autotrash

It's no big deal to empty the Recycle Bin or press SHIFT+DELETE to permanently delete the useless stuff in the Linux system. It only takes a few seconds. However, if you need additional programs to deal with junk files, Autotrash may be helpful. Try it and see how it works.

Summary

The above is the whole content of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. Thank you for your support. If you want to know more about it, please see the relevant links below.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report