Is this a robust way to distinguish explicitly installed packages from those pulled in as dependencies?
When exploring the commands from this answer to my previous question, I found that the ist of packages includes a lot that were automatically installed due to dependencies. Obviously I'm interested only in those packages that I explicitly requested (the others would be pulled in automatically again, if needed).
Since I didn't figure out a way to explicitly query whether a package was installed explicitly or as dependency, I figured the best way would be to determine whether a package depends on another installed package.
This information turns out to be available with apt-cache rdepends --installed $packagename
but I still need to extract the information I need from the output.
Unfortunately the line "Reverse Depends:" is always output, even if there are no reverse dependencies. However I noticed that the dependency lines all start with a space, while the others don't. Therefore my idea is to use the following:
apt-cache rdepends --installed $packagename | grep -q "^ "
If there are no dependencies, the exit status of grep will be 1, otherwise it will be 0.
My question now is: Is this a robust way to test for this? If not, what are better ways to achieve what I want?
1 answer
apt-mark
aims to do this: the commands apt-mark showmanual
and apt-mark showauto
should show you respectively the packages which you explicitly installed and the ones which were added as dependencies.
There are caveats.
- There seems to be a common complaint that it shows too many packages as manual; it's possible that running
apt-mark minimize-manual
would address that complaint. - It's quite likely that some of the initially installed packages will be marked as manual, because
apt autoremove
will remove any package marked as auto which isn't a dependency of a package marked as manual. Runningapt-mark showmanual
at install and saving for future comparison would largely address this issue.
0 comment threads