A script to clean files in the trashcan that have been kept for more than a specified number of days.

PJ568 1b66e60569 【新增】优化内存使用以降低峰值消耗 1 سال پیش
.github b56cc0946e 【维护】更新版本号和工作流配置 1 سال پیش
scripts 62ff2854de 【新增】添加自动发行版本的 GitHub Actions 工作流 1 سال پیش
.gitignore f4f47e9956 【修复,配置】修复 shell 脚本中的字符串比较并更新忽略列表 1 سال پیش
CONTRIBUTING.md 694df065f9 【初始】创建回收站清理脚本及测试 1 سال پیش
LICENSE 694df065f9 【初始】创建回收站清理脚本及测试 1 سال پیش
README.en.md 69eb14c3fd 【新增】添加版本号显示功能 1 سال پیش
README.md 69eb14c3fd 【新增】添加版本号显示功能 1 سال پیش
clean_trash.sh 1b66e60569 【新增】优化内存使用以降低峰值消耗 1 سال پیش

README.en.md

Trash Cleaner Script

简体中文 | English

A script to clean files in the trash that have been kept for more than a specified number of days.

Project URL: https://github.com/PJ-568/clean_trash

Installation and Usage

Method 1: Direct Script Usage

Trash Cleaner Tool
Usage: ./clean_trash.sh [-h] [-v] [-V] <days to keep>
Options:
  -h  Show help message
  -v  Verbose output mode
  -V  Show version
Examples:
  ./clean_trash.sh 30        # Clean trash files older than 30 days
  ./clean_trash.sh -v 7      # Verbose mode to clean files older than 7 days
  ./clean_trash.sh -V        # Show version information

Method 2: System Installation (Recommended)

The installation script will copy clean_trash.sh to /usr/local/bin/clean_trash and create a systemd service (not enabled by default):

# Remote installation from GitHub (without cloning the repository)
curl -sS https://raw.githubusercontent.com/PJ-568/clean_trash/master/scripts/install.sh | bash

# Or clone the repository and install locally
git clone https://github.com/PJ-568/clean_trash.git
cd clean_trash
sudo ./scripts/install.sh

# Enable daily automatic cleanup (files older than 30 days)
sudo systemctl enable --now clean-trash.timer

Uninstallation

# Uninstall
curl -sS https://raw.githubusercontent.com/PJ-568/clean_trash/master/scripts/uninstall.sh | bash

Contributing

Contribution Guide

Overview of Linux Trash Mechanism

When you "delete" a file in a Linux desktop environment, it moves the file to a special "trash" directory, which is usually ~/.local/share/Trash/. The trash directory typically contains three subdirectories:

  • files/: Stores the deleted files themselves. For example: question.png.
  • info/: Stores metadata related to the deleted files (such as the original path, deletion timestamp, etc.). For example:

    [Trash Info]
    Path=/home/user/question.png
    DeletionDate=2025-08-13T19:47:35
    
  • expunged/: Temporarily stores files that are to be permanently deleted.

Purpose of the expunged Folder

  • "Permanent Deletion" Operation: When you decide to empty the trash (select the "Empty Trash" menu item in the file manager), the desktop environment does not simply delete all the contents of the files/ and info/ directories.
  • Marking Process: It first moves the corresponding files in the files/ directory to the ~/.local/share/Trash/expunged/ directory (because moving files is fast).
  • Physical Deletion: Then, it physically deletes the corresponding metadata files in the info/ directory; and slowly physically deletes the corresponding files in the expunged/ directory (deleting a large number of files takes time, and doing it too quickly may slow down the entire computer).