8

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.

2 Answers 2

5

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.
2
  • 1
    Yes, this helps. If I wanted to do it entirely from command line, I think I could use apt-get -V --no-download -s dist-upgrade | grep "^ .*" | cut -d"(" -f1 Jun 12, 2018 at 20:13
  • But I'll have python so just getting the -V, and noting that all new/updated packages are preceded by unique whitespace, is enough to make them easily parseable. Jun 12, 2018 at 20:13
2

Is apt-show-versions -u what you are looking for? From its manpage:

-u, --upgradeable

    Print only upgradeable packages

List all packages available for upgrade in a text file and display them in column format:

apt-show-versions -u | column -t > debupdlist-$(date '+%Y%m%d').txt

List the names of upgradeable packages:

apt-show-versions -u | cut -d: -f1 
4
  • Does this always produce the same list of package that would actually get upgraded? What if there's a newer version of a package but it can't be installed due to missing dependencies or conflicts? What about pins? What about held packages? Jun 12, 2018 at 19:26
  • I don't even have an apt-show command on my current install. Must be an extra/optional package that provides that? Jun 12, 2018 at 20:09
  • @TravisGriggs The command is apt-show-versions, from the package of the same name.
    – Spooky
    Oct 17, 2018 at 5:35
  • what you are looking for? He explicitly asked for apt-get, but one can infer that he was just evading apt's inconsistent output by any other solution
    – polendina
    Aug 17, 2022 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.