How to get list of to-be-upgraded packages using apt-get

aptsoftware-updates

I am curious if there is a script friendly way to compute the equivalent of apt list --upgradeable. That produces a nice output with exactly one upgrade candidate per line, very parseable. BUT, apt also warns:

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

So I feel I should use venerable apt-get instead. Unfortunately, the output for that looks something like:

apt-get -s --no-download dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
  dbus libdbus-1-3
The following packages will be upgraded:
  bash gcc-8-base gpgv libedit2 libgcc1 libprocps7 libpsl5 libselinux1 libsemanage-common libsemanage1 libsepol1 libsqlite3-0 libstdc++6 perl-base
  procps publicsuffix rsyslog twigpilot-core
18 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
...

Which is much less parseable. So I was hoping for some way to get apt-get update to print a more succinct list like apt would.

Best Answer

I don't use Ubuntu regularly but how about this:

$ apt-get -s --no-download dist-upgrade -V | grep '=>' | awk '{print$1}'

It prints one package per line. As described in man apt-get:

   -V, --verbose-versions
       Show full versions for upgraded and installed packages. Configuration Item: APT::Get::Show-Versions.
Related Question