I installed xinit and ubuntu-desktop on my web server as an experiment. I want to remove them, so I ran apt-get autoremove
for each of them. Much less space was freed than was used in installation. I was going to remove all the packages, but my terminal won't scroll up far enough to see the dependencies that were also installed. Is there a record of which dependencies were installed, so that I can remove them? If not, is there a general list of dependencies? I hadn't installed much before that besides apache and some python packages, so maybe there's a list of which packages I should remove? I used nearly 2.5% of my available 20GB installing these.
Asked
Active
Viewed 116 times
0

Luke Taylor
- 101
1 Answers
0
I used this Python script to parse the log file for all the packages that were installed as dependencies of xinit
and 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)
Then, I pasted the output on the end of an apt-get autoremove
. The output made me very happy:
About a minute later, the packages had all been removed! Thanks for your help, @theodorn.

Luke Taylor
- 101
sudo apt-get clean
orsudo apt-get autoclean
? – theodorn Jan 19 '16 at 20:54/var/log/apt/history.log
file. – theodorn Jan 19 '16 at 21:03apt-get install xinit
installedxserver-xorg-video-vmware
, and remove that. I'm writing a python script to organize the full list in a copy/pasteable format. – Luke Taylor Jan 19 '16 at 21:17