简体中文 | English
实现清理在回收站里保存超过指定天数的文件。
项目地址:https://github.com/PJ-568/clean_trash
回收站清理工具
用法:./clean_trash.sh [-h] [-v] [-V] <保留天数>
选项:
-h 显示帮助信息
-v 详细输出模式
-V 显示版本信息
示例:
./clean_trash.sh 30 # 清理 30 天前的回收站文件
./clean_trash.sh -v 7 # 详细模式清理 7 天前文件
./clean_trash.sh -V # 显示版本信息
安装脚本会将 clean_trash.sh 复制到 /usr/local/bin/clean_trash 并创建 systemd 服务(默认不启用):
# 从 GitHub 远程安装(无需克隆仓库)
curl -sS https://raw.githubusercontent.com/PJ-568/clean_trash/master/scripts/install.sh | bash
# 或者克隆仓库后本地安装
git clone https://github.com/PJ-568/clean_trash.git
cd clean_trash
sudo ./scripts/install.sh
# 启用每天自动清理(超过 30 天的文件)
sudo systemctl enable --now clean-trash.timer
# 卸载
curl -sS https://raw.githubusercontent.com/PJ-568/clean_trash/master/scripts/uninstall.sh | bash
Linux 桌面环境“删除”一个文件时会将它移动到一个特殊的“回收站”目录中,这个目录通常是 ~/.local/share/Trash/。
回收站目录内部通常有三个子目录:
files/: 存放被删除的文件本身。如:提问.png。info/: 存放与被删除文件相关的元数据(如原始路径、删除时间戳等)。如:
[Trash Info]
Path=/home/user/%E6%8F%90%E9%97%AE.png
DeletionDate=2025-08-13T19:47:35
expunged/: 临时存放要被永久删除的文件。
expunged 文件夹的作用files/ 和 info/ 目录里的所有内容。files/ 目录中对应的文件移动到 ~/.local/share/Trash/expunged/ 目录中(因为移动文件很快)。info/ 目录中对应的元数据文件;慢慢物理删除 expunged/ 目录中对应的文件(删除大量文件需要时间,过快地进行可能会减慢整个计算机的速度)。