在WSL中安装Unity桌面,安装了近2G的依赖包,卸载Unity桌面后这些包大部分无法自动删除,apt 没有提供”回滚“这种操作,所以,只能自己找到安装的依赖包(近1k个)删除。
apt将安装历史保存在 /var/log/apt/history.log 下
cat -n /var/log/apt/history.log | grep '2018-04-08' -A 2 | more
grep找到在300行有安装依赖的信息:
300-Install: dvd+rw-tools:amd64 (7.1-10build1, automatic), unity-control-center-signon:amd64 (0.1.7~+14.04.20140211.2-0ubuntu4, automatic), growisofs:amd64 (7.1-10build1, automatic), python3-pyatspi:amd64 (2.10.0+dfsg-1, automatic), dc:amd64 (1.06.95-8ubuntu1, automatic), python3-pyparsing:amd64 (2.0.1+dfsg1-1build1, automatic), libgoa-1.0-0b:amd64 (3.10.3-0ubuntu1, automatic), syslinux-legacy:amd64 (3.63+dfsg-2ubuntu5, automatic), xfonts-mathml:amd64 (6ubuntu1, automatic), friends-twitter:amd64 (0.2.0+14.04.20140217.1-0ubuntu1, automatic), telepathy-haze:amd64 (0.8.0-1, automatic), libxkbcommon-x11-0:amd64 (0.4.1-0ubuntu1, automatic), gir1.2-atk-1.0:amd64 (2.10.0-2ubuntu2, automatic), ibus-table:amd64 (1.5.0.is.1.5.0.20130419-2), libtotem-plparser18:amd64 (3.10.2-0ubuntu1, automatic), unity-scope-audacious:amd64 (0.1+13.10.20130927.1-0ubuntu1, automatic), brasero-cdrkit:amd64 (3.10.0-0ubuntu1, automatic), oxideqt-codecs:amd64 (1.21.5-0ubuntu0.14.04.1, automatic), ...
用sed删除 'Install:' 这个头,然后按空格分行,然后删除所有带(和)的行,最后再把所有行合并成一行,传给apt-get
sudo apt-get purge `sed -n 300p /var/log/apt/history.log | sed 's/Install://' | sed 's/\ /\n/g' | sed '/(/d' | sed '/)/d' | sed ':l;N;s/\n/ /;b l'`
最后再autoremove一下
sudo apt-get autoremove
这样,就把磁盘空间全部归还了