在Ubuntu系统中,设置回收站容量限制通常涉及到文件系统的配额管理。以下是一些常见的方法:
sudo apt-get install quota # Debian/Ubuntu
sudo yum install quota # CentOS/RHEL
/etc/fstab
文件,为需要设置配额的分区添加 usrquota
和 grpquota
选项。例如:/dev/sda1 /home ext4 defaults,usrquota,grpquota 1 2
然后重新挂载分区:
sudo mount -o remount /home
sudo quotacheck -cum /home
sudo quotaon -vug /home
edquota
命令为用户设置配额。例如:sudo edquota -u username
在编辑器中设置软限制和硬限制:
Disk quotas for user username (uid 1000):
Filesystem blocks soft hard inodes soft hard
/dev/sda1 102400 50000 60000 1000 2000 2500
如果你不想使用quota工具,可以编写一个自定义脚本来监控和限制回收站的容量。
#!/bin/bash
RECYCLE_BIN="/path/to/recycle/bin"
MAX_SIZE=104857600 # 100MB in bytes
while true; do
total_size=$(du -sb "$RECYCLE_BIN" | awk '{print $1}')
if [ "$total_size" -gt "$MAX_SIZE" ]; then
# Remove oldest files until size is within limit
find "$RECYCLE_BIN" -type f -printf '%T@ %p
' | sort -n | cut -d ' ' -f 2- | head -n 1 | xargs rm -rf
fi
sleep 60
done
chmod +x /path/to/monitor_script.sh
nohup /path/to/monitor_script.sh &
如果你使用的是 trash-cli
来管理回收站,可以结合 cron
任务来定期清理。
sudo apt-get install trash-cli # Debian/Ubuntu
sudo yum install trash-cli # CentOS/RHEL
#!/bin/bash
TRASH_DIR="$HOME/.local/share/Trash/files"
MAX_SIZE=104857600 # 100MB in bytes
total_size=$(du -sb "$TRASH_DIR" | awk '{print $1}')
if [ "$total_size" -gt "$MAX_SIZE" ]; then
# Remove oldest files until size is within limit
find "$TRASH_DIR" -type f -printf '%T@ %p
' | sort -n | cut -d ' ' -f 2- | head -n 1 | xargs rm -rf
fi
chmod +x /path/to/cleanup_script.sh
crontab -e
添加以下行以每小时运行一次清理脚本:
0 * * * * /path/to/cleanup_script.sh