Ubuntu回收站设置技巧汇总
dconf-editor
工具修改(需安装:sudo apt install dconf-editor
),依次展开org->gnome->desktop->nautilus->trash
,找到max-size
选项,双击输入回收站最大大小(单位:字节,如1GB=1073741824)。修改后自动生效。xfconf-query -c xfce4-trash -p /trash/max-size -s 100M
。trash-cli
(sudo apt install trash-cli
),创建清理脚本(如clean_recycle_bin.sh
),内容示例:#!/bin/bash
MAX_FILES=100 # 最大文件数
MAX_SIZE=100 # 最大容量(MB)
CURRENT_FILES=$(ls -1 ~/.local/share/Trash/files/* | wc -l)
CURRENT_SIZE=$(du -sm ~/.local/share/Trash/files | awk '{print $1}')
if [ "$CURRENT_FILES" -gt "$MAX_FILES" ] || [ "$CURRENT_SIZE" -gt "$MAX_SIZE" ]; then
trash-empty
fi
赋予执行权限(chmod +x clean_recycle_bin.sh
),通过crontab -e
设置定时任务(如每天凌晨1点运行:0 1 * * * /path/to/script.sh
)。autotrash
(sudo apt install autotrash
),可自动清理超过指定天数的文件(如每天清理30天前的文件):autotrash -d 30
。可将此命令添加到cron中实现定期执行。rm -rf ~/.local/share/Trash/*
trash-cli
:trash-empty
(需安装)。Ubuntu回收站默认无自动过期设置,但可通过以下方式实现:
0 0 1 * * /path/to/empty_trash.sh
,或使用autotrash
设置天数阈值。若系统重装或恢复出厂设置,需重新配置回收站:
nautilus
文件管理器安装(默认包含);gconf-editor
设置(需安装:sudo apt install gconf-editor
),依次展开apps->nautilus->desktop
,勾选trash_icon_visible
选项,即可在桌面显示回收站图标。