Why does apt-cache search have wrong output?

Solution 1:

The answer seems to be that even with the addition of --names-only, the apt-cache search command searches the packages' provided packages. From man apt-cache:

   search regex...
       search performs a full text search on all available package lists
       for the POSIX regex pattern given, see regex(7). It searches the
       package names and the descriptions for an occurrence of the regular
       expression and prints out the package name and the short
       description, including virtual package names. If --full is given
       then output identical to show is produced for each matched package,
       and if --names-only is given then the long description is not
       searched, only the package name and provided packages are.

We can see exactly what the search is matching as follows:

$ apt-cache search --names-only '^linux-' | grep -v '^linux-' |
    while read -r pkg rem; do apt-cache show "$pkg" | grep -H --label="$pkg" '^Provides:'; done
busybox-syslogd:Provides: linux-kernel-log-daemon, system-log-daemon
busybox-syslogd:Provides: linux-kernel-log-daemon, system-log-daemon
busybox-syslogd:Provides: linux-kernel-log-daemon, system-log-daemon
initramfs-tools:Provides: linux-initramfs-tool
initramfs-tools:Provides: linux-initramfs-tool
initramfs-tools:Provides: linux-initramfs-tool
rsyslog:Provides: linux-kernel-log-daemon, system-log-daemon
rsyslog:Provides: linux-kernel-log-daemon, system-log-daemon
dracut:Provides: linux-initramfs-tool
inetutils-syslogd:Provides: linux-kernel-log-daemon, system-log-daemon
socklog-run:Provides: linux-kernel-log-daemon, system-log-daemon
syslog-ng-core:Provides: libsyslog-ng-dev, linux-kernel-log-daemon, syslog-ng-mod-journal, system-log-daemon
tiny-initramfs:Provides: linux-initramfs-tool