How to remove Debian packages with help of vi magic

Okay, the headline is not really the full truth, but with the help of vi you can do some cool things.

I had installed “graphviz” on one of my servers, because I thought I could create a dot file. For some reason [...] that did not work and so I decided to remove this package again. I wanted it really clean.

Normally someone would just do something like

apt-get autoremove –purge graphviz

but sometimes that does not remove all previously installed dependencies.

All package stuff gets logged to /var/log/apt/history.log. At least here on Ubuntu Lucid ;-)

So you may find a block like the following one:

Start-Date: 2011-10-23  14:41:00
Install: libts-0.0-0 (1.0-7build1), xfonts-encodings (1.0.3-1), ttf-dejavu-core (2.30-2), ttf-liberation (1.05.2.20091019-4), libcairo2 (1.8.10-2ubuntu1), xfonts-utils (7.5+2), libthai-data (0.1.13-1build1), libdirectfb-1.2-0 (1.2.8-5ubuntu2), libdatrie1 (0.2.2-3), fontconfig (2.8.0-2ubuntu1), libxfont1 (1.4.1-1ubuntu0.1), libpango1.0-common (1.28.0-0ubuntu2.2), libpixman-1-0 (0.16.4-1ubuntu2), libxaw7 (1.0.7-1), libgraphviz4 (2.20.2-8ubuntu3), libxft2 (2.1.14-1ubuntu1), fontconfig-config (2.8.0-2ubuntu1), libice6 (1.0.6-1), libthai0 (0.1.13-1build1), libxmu6 (1.0.5-1), libxpm4 (3.5.8-1), libxrender1 (0.9.5-1), x-ttcidfont-conf (32), libfontenc1 (1.0.5-1), libjpeg62 (6b-15ubuntu1), tsconf (1.0-7build1), x11-common (7.5+5ubuntu1), libsysfs2 (2.1.0-6), libfontconfig1 (2.8.0-2ubuntu1), libpango1.0-0 (1.28.0-0ubuntu2.2), libsm6 (1.1.1-1), libxcb-render0 (1.5-2), libxt6 (1.0.7-1), defoma (0.11.10-4ubuntu1), graphviz (2.20.2-8ubuntu3), libxcb-render-util0 (0.3.6-1build1), libgd2-noxpm (2.0.36~rc1~dfsg-3.1ubuntu1)
End-Date: 2011-10-23  14:41:10

Simply copy this code into a file and open it with vi. Now type the following command:

:%s/\( ([\.0-9a-z\-+~]\+),\?\)//g

Remove the Install: and the Start and End line. Save it.

Now:

cat filename | xargs apt-get autoremove --purge -y

No guarantees, have fun…


-- Download How to remove Debian packages with help of vi magic als PDF --


Leave a Comment