Which packages recommended 'Missing Recommends'?

The Synaptic Package Manager has a custom filter "Missing Recommends". Is there a way to find out which packages installed on my system recommended the packages listed in this filter?


Solution 1:

Aptitude can perform some fairly fancy searches

This will show all the packages that have a Recommends that isn't satisfied:

aptitude search '?installed?broken-recommends'

To restrict it to a specific recommended package:

aptitude search '?installed?broken-recommends(PACKAGE)'

Solution 2:

As far as I know there is no easy way to find out which package recommends a specific other package.

Here is a crude script to build a list of what package recommends or suggests what other package:

dpkg --get-selections | cut -f 1 | while read pkgname
do
  apt-cache depends "$pkgname" | \
  grep -E "Recommends|Suggests" | \
  cut -b 3- | \
  while read recommends
  do
    echo "$pkgname" "$recommends"
  done
done | sort -k 3 -k 2 | column -t

Note: the script takes some to run. Also the output is very long so you very likely want to capture the output in a file:

$ whatrecommends.sh > whatrecommends.txt

Sample of output:

...
ubuntu-desktop                    Recommends:  avahi-autoipd
avahi-daemon                      Suggests:    avahi-autoipd
dhcp3-client                      Suggests:    avahi-autoipd
libnss-mdns                       Suggests:    avahi-autoipd
hplip                             Recommends:  avahi-daemon
rhythmbox                         Recommends:  avahi-daemon
ubuntu-desktop                    Recommends:  avahi-daemon
libsane                           Suggests:    avahi-daemon
pulseaudio-utils                  Suggests:    avahi-daemon
sane-utils                        Suggests:    avahi-daemon
system-config-printer-common      Recommends:  avahi-utils
bash                              Recommends:  bash-completion
ubuntu-standard                   Recommends:  bash-completion
ack-grep                          Suggests:    bash-completion
bash                              Suggests:    bash-doc
...

By changing the parameters of sort at the end of the script you can change the sort order of the output.

Solution 3:

Based on tumbleweed's answer, I made a script that uses aptitude searches to come up with the packages which recommend a missing package.

It however doesn't give the same, complete list as synaptic. No idea why.

The script

#!/usr/bin/php
<?php

$list = shell_exec("aptitude search '?broken-reverse-recommends(?installed)'");
preg_match_all("|^.{4}(.*) - (.*)$|mU", $list, $matches);

foreach ($matches[1] as $prog) {
    $prog = trim($prog);
    echo "$prog:\n";
    $missing = shell_exec("aptitude search '?installed?broken-recommends($prog)'");
    preg_match_all("|^.{4}(.*) - (.*)$|mU", $missing, $mismatch);
    foreach ($mismatch[1] as $missoft) {
        echo "\tRecommended by: ".trim($missoft)."\n";
    }
}

Sample output

ecryptfs-utils:
    Recommended by: adduser
firefox:
    Recommended by: xubuntu-desktop
    Recommended by: xul-ext-ubufox
firefox-gnome-support:
    Recommended by: xubuntu-desktop
libatm1:
    Recommended by: iproute

Solution 4:

Here, my way - report for missing recommends :)

apt-cache --no-pre-depends --no-depends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances depends `dpkg --get-selections | grep '\sinstall$' | cut -f1` | grep -vf <(dpkg --get-selections | grep '\sinstall$' | cut -f1 | sed -e 's/^/ /' -e 's/\(:.*\|\)$/$/') | grep -B1 '^ '

Solution 5:

Get a list of installed packages with missing recommended package:

aptitude search '?installed?broken-recommends'

Get a list of not installed, missing packages that are recommended by installed packages - "missing recommends":

aptitude search '?broken-reverse-recommends(?installed)'

Get which package is recommending a specific "missing recommend":

aptitude search '?installed?broken-recommends(MISSING_PKG_NAME)'

One liner: For all "missing recommends", get by which packages are recommended:

for p in $(aptitude search -F%p '?broken-reverse-recommends(?installed)'); do echo $p; aptitude search "?installed?broken-recommends($p)"; done

You can find "missing recommends" in Synaptic package manager. (As I see, Synaptic shows also the missing Suggested packages.)

You can install all "missing recommends" with one command but I do not recommend it! First, review the list of packages before install. (For example, fresh install of debian buster shows missing "default-mta", which is a virtual package.)

apt install $(aptitude search -F%p '?broken-reverse-recommends(?installed)')

(This is summary from few similar questions and answers. Hope it will help someone else.)