2

I'm trying to see witch packages I've installed, but when I dpkg -l I got a big list of packages and their packages dependencies.

There's a way to get only the list of packages explicitly installed?

Ex:

apt-get install mysql-server

Thats also installs mysql-common

I want that when i list my packages only the mysql-server is showed.

  • Is maybe apt-mark showmanual your thing? this lists all packages which have been marked manually installed. – Videonauth Nov 26 '17 at 07:53
  • Nope, its also listing package dependencies. – Eleandro Duzentos Nov 26 '17 at 07:55
  • Look into apt-mark; however I think it will also show packages that were installed during the initial installation of Ubuntu. – fkraiem Nov 26 '17 at 07:55
  • I think without coding your own solution which uses apt show to determine which are dependencies and which are roots/endpoints of those trees you wont get that tbh. – Videonauth Nov 26 '17 at 07:56
  • Ok guys, here is a solution: cat /var/log/apt/history.log | grep 'apt-get install '. – Eleandro Duzentos Nov 26 '17 at 08:07
  • @e200 nice. But I have definitely at least one package shown by dpkg -l which I downloaded as a .deb-file and installed directly by the software manager. This package is not listed by your solution. – muclux Nov 26 '17 at 08:53
  • @e200 and this works only if you not have cleaned logs meanwhile after installation. – Videonauth Nov 26 '17 at 08:58
  • @Videonauth I tried your suggestion and still get 295 packages (including things like fonts, user guides and docs, gnome games, ...) – muclux Nov 26 '17 at 08:58
  • I know this is why my next comment suggested a script solution to that, checking each package for if it is a top node. – Videonauth Nov 26 '17 at 09:01
  • I meant the script solution. apt-mark showmanual listed 1574 packages. – muclux Nov 26 '17 at 09:03
  • 1
    @muclux this is not a script solution, this is a simple command the system has, I was talking about taking this output into a script and then checking each package if it has dependencies deleting the dependencies out until only top nodes are left. – Videonauth Nov 26 '17 at 09:16
  • @muclux, looks like your suggestion will work, but it will take a lot of time to implement. – Eleandro Duzentos Nov 26 '17 at 09:32
  • 2
    @e200 @Videonauth I first wrote a script to get all installed packages and extract their dependencies. Then it takes all packages and checks whether they appear in the Depends: list of another package. This leaves me the 295 packages mentioned above. Now I changed my script to check only the packages given by apt-mark showmanual. This reduces the output to 256 packages. – muclux Nov 26 '17 at 09:42
  • @muclux then you might want to present an answer here, and if you want it to be even more fine grained you can take the manifest into account and remove the top nodes mentioned there. – Videonauth Nov 26 '17 at 09:45
  • However the best solution is to keep hand made logs of what you installed, this is what I do for example sudo apt install <package> && echo "<package>" >> install.log. Yes its a bit more typing but pays out in the long run if I ever have to redo my system. – Videonauth Nov 26 '17 at 09:57

2 Answers2

3

Here is my quick-and-dirty script discussed in the comments to the original post, following the ideas of @Videonauth (as I understood them). The list of the remaining packages is written to the file top_packages.

(It takes some time to run).

#!/bin/bash

echo > dependencies
echo > top_packages
dpkg -l | egrep '^..  ' | cut -f3 -d' ' | cut -f1 -d':' > packages

for i in `cat packages`
do
    echo collecting dependencies of package $i
    apt show $i 2> /dev/null | grep Depends >> dependencies
done

for i in `apt-mark showmanual`
do
    grep -q $i dependencies || echo $i | tee -a top_packages
done
Videonauth
  • 33,355
  • 17
  • 105
  • 120
muclux
  • 5,154
2

This solution helps me:

cat /var/log/apt/history.log | grep 'apt-get install '