废话不多说,上代码
export root= # 卸载孤立包 apt autoremove -y # 保留1天系统日志 journalctl --vacuum-time=1d # 清空登录提示 > $root/etc/motd # 清空登录记录 > $root/var/log/wtmp > $root/var/log/btmp > $root/var/log/lastlog > $root/var/log/faillog # 重置机器特征 > $root/etc/machine-id > $root/var/lib/dbus/machine-id # 删除邮件名称 rm -f $root/etc/mailname # 删除命令历史 rm -f $root/root/.bash_history find $root/home -name .bash_history -delete # 删除包缓存 rm -rf $root/var/cache/apt/* rm -rf $root/var/lib/apt/lists/* rm -rf $root/var/lib/dpkg/available* # 删除安装记录 rm -f $root/var/log/apt/* rm -f $root/var/log/dpkg.log rm -f $root/var/log/bootstrap.log rm -f $root/var/log/alternatives.log rm -f $root/var/log/install_packages.list rm -f $root/etc/apt/sources.list.d/localdebs.list # 删除系统日志 rm -f $root/var/log/debug rm -f $root/var/log/messages rm -f $root/var/log/syslog rm -rf $root/var/log/journal find $root/var/log -name *.log -delete # 删除归档文件 find $root/etc -type f -name *~ -delete find $root/etc -type f -name *- -delete find $root/var -type f -name *-old -delete find $root/var/log -type f -name *.[0-9] -delete find $root/var/log -type f -name *.gz -delete find $root/var/log -type f -name *.xz -delete