我在我的 Web 服务器上安装了 xinit 和 ubuntu-desktop 作为实验。我想删除它们,所以我apt-get autoremove
对它们每个都运行了一次。释放的空间比安装时使用的空间少得多。我打算删除所有软件包,但我的终端无法向上滚动到足以看到已安装的依赖项。是否有已安装依赖项的记录,以便我可以删除它们?如果没有,是否有依赖项的一般列表?在此之前,除了 apache 和一些 python 软件包之外,我没有安装太多东西,所以也许有一个我应该删除哪些软件包的列表?安装这些软件包时,我使用了近 20GB 可用空间的 2.5%。
答案1
xinit
我使用这个 Python 脚本来解析作为和依赖项安装的所有包的日志文件ubuntu-desktop
:
REMOVETHESE='xinit','ubuntu-desktop'
#Return an input string with everything parenthesized removed.
def removeParenthesized(inp):
while "(" in inp:
opening=inp.find("(")-1
ending=inp.find(")")+1
inp=inp[:opening]+inp[ending:]
return inp
#Load the log file
with open("/var/log/apt/history.log","r") as logfile:
log=logfile.read()
#Separate each log entry.
entries=log.split("\n\n")
#Dict pairs the name of an installed package with the full log entry for that installation
entries={e.split("\n")[1].split(" ")[-1] : "\n".join(e.split("\n")[2:-2])[8:] for e in entries if e.split("\n")[1].split(" ")[2]=="install"}
#Entries of packages to remove
toRemove=[entries[rt] for rt in REMOVETHESE]
#To be removed
removals=[]
for entry in toRemove:
#Remove the parenthesized information
entry = removeParenthesized(entry)
#Split entries by comma, removing the initial space
packages = [e[1:] for e in entry.split(',')]
#Remove the info after the colon
packages=[p.split(':')[0] for p in packages]
#Add dependencies for this package to list
removals.extend(packages)
#Print all dependencies
print ' '.join(removals)
然后,我将输出粘贴到 的末尾apt-get autoremove
。输出让我非常高兴:
大约一分钟后,所有软件包都被删除了!感谢您的帮助,@theodorn。