Ubuntu Recycle(通常指的是Ubuntu的回收站)本身并沒有直接提供自動清理的功能。不過,你可以通過幾種方法來實現Ubuntu系統的自動清理。
trash-cli
和 cron
trash-cli
:sudo apt update
sudo apt install trash-cli
clean_recycle_bin.sh
,并添加以下內容:#!/bin/bash
# 設置回收站的最大文件數
MAX_FILES=100
# 獲取當前回收站中的文件數
FILE_COUNT=$(ls -1 ~/.local/share/Trash/files/* | wc -l)
# 如果文件數超過最大值,則清空回收站
if [ "$FILE_COUNT" -gt "$MAX_FILES" ]; then
trash-empty
fi
chmod +x clean_recycle_bin.sh
cron
來定期運行這個腳本。編輯 crontab
文件:crontab -e
添加以下行來每天凌晨1點運行腳本:
0 1 * * * /path/to/clean_recycle_bin.sh
將 /path/to/clean_recycle_bin.sh
替換為你實際的腳本路徑。
autotrash
命令行實用程序autotrash
:sudo apt-get update
sudo apt-get install autotrash
autotrash
:autotrash -d [days]
autotrash --max-free [M兆字節] -d [天數]
autotrash --delete [M兆字節]
#!/bin/bash
# 設置回收站的最大大?。ㄒ訫B為單位)
MAX_SIZE=100
# 獲取回收站的總大小
TOTAL_SIZE=$(du -sm ~/.local/share/Trash/files | awk '{print $1}')
# 如果總大小超過最大值,則清空回收站
if [ "$TOTAL_SIZE" -gt "$MAX_SIZE" ]; then
trash-empty
fi
chmod +x clean_recycle_bin.sh
cron
來定期運行這個腳本。編輯 crontab
文件:crontab -e
添加以下行來每天凌晨1點運行腳本:
0 1 * * * /path/to/clean_recycle_bin.sh
將 /path/to/clean_recycle_bin.sh
替換為你實際的腳本路徑。
通過以上方法,你可以自定義Ubuntu Recycle的自動清理規則,以滿足你的特定需求。