Categories
SysOps

How to display available updates

It is straightforward to display available updates using an application with a graphical user interface, but not so obvious to do it by using shell commands only. I will shed some useful light on the subject so we could both benefit from it.

To quickly display available updates, you need to simulate upgrade action and then filter for unpack (Inst) operation.

$ apt-get -s dist-upgrade | grep ^Inst
Inst openjdk-7-jre [7u3-2.1.7-1] (7u25-2.3.10-1~deb7u1 Debian-Security:7.0/stable [amd64]) []
Inst icedtea-7-jre-jamvm [7u3-2.1.7-1] (7u25-2.3.10-1~deb7u1 Debian-Security:7.0/stable [amd64]) []
Inst openjdk-7-jre-headless [7u3-2.1.7-1] (7u25-2.3.10-1~deb7u1 Debian-Security:7.0/stable [amd64]) []
Inst openjdk-7-jre-lib [7u3-2.1.7-1] (7u25-2.3.10-1~deb7u1 Debian-Security:7.0/stable [all])
Inst openjdk-6-jre [6b27-1.12.5-1] (6b27-1.12.6-1~deb7u1 Debian-Security:7.0/stable [amd64]) []
Inst icedtea-6-jre-jamvm [6b27-1.12.5-1] (6b27-1.12.6-1~deb7u1 Debian-Security:7.0/stable [amd64]) []
Inst icedtea-6-jre-cacao [6b27-1.12.5-1] (6b27-1.12.6-1~deb7u1 Debian-Security:7.0/stable [amd64]) []
Inst openjdk-6-jre-headless [6b27-1.12.5-1] (6b27-1.12.6-1~deb7u1 Debian-Security:7.0/stable [amd64]) []
Inst openjdk-6-jre-lib [6b27-1.12.5-1] (6b27-1.12.6-1~deb7u1 Debian-Security:7.0/stable [all])
Inst dnsutils [1:9.8.4.dfsg.P1-6+nmu2] (1:9.8.4.dfsg.P1-6+nmu2+deb7u1 Debian-Security:7.0/stable [amd64]) []
Inst bind9-host [1:9.8.4.dfsg.P1-6+nmu2] (1:9.8.4.dfsg.P1-6+nmu2+deb7u1 Debian-Security:7.0/stable [amd64]) []
Inst libisc84 [1:9.8.4.dfsg.P1-6+nmu2] (1:9.8.4.dfsg.P1-6+nmu2+deb7u1 Debian-Security:7.0/stable [amd64]) []
Inst libdns88 [1:9.8.4.dfsg.P1-6+nmu2] (1:9.8.4.dfsg.P1-6+nmu2+deb7u1 Debian-Security:7.0/stable [amd64]) []
Inst libisccc80 [1:9.8.4.dfsg.P1-6+nmu2] (1:9.8.4.dfsg.P1-6+nmu2+deb7u1 Debian-Security:7.0/stable [amd64]) []
Inst libisccfg82 [1:9.8.4.dfsg.P1-6+nmu2] (1:9.8.4.dfsg.P1-6+nmu2+deb7u1 Debian-Security:7.0/stable [amd64]) []
Inst liblwres80 [1:9.8.4.dfsg.P1-6+nmu2] (1:9.8.4.dfsg.P1-6+nmu2+deb7u1 Debian-Security:7.0/stable [amd64]) []
Inst host [1:9.8.4.dfsg.P1-6+nmu2] (1:9.8.4.dfsg.P1-6+nmu2+deb7u1 Debian-Security:7.0/stable [all]) []
Inst libbind9-80 [1:9.8.4.dfsg.P1-6+nmu2] (1:9.8.4.dfsg.P1-6+nmu2+deb7u1 Debian-Security:7.0/stable [amd64])

The preceding example does not provide a very readable output, so simplify it a bit.

$ apt-get -s dist-upgrade | grep ^Inst | cut -d\  -f2 | sort
bind9-host
dnsutils
host
icedtea-6-jre-cacao
icedtea-6-jre-jamvm
icedtea-7-jre-jamvm
libbind9-80
libdns88
libisc84
libisccc80
libisccfg82
liblwres80
openjdk-6-jre
openjdk-6-jre-headless
openjdk-6-jre-lib
openjdk-7-jre
openjdk-7-jre-headless
openjdk-7-jre-lib

Alternatively, you can create a longer chain of commands to pretty-print the desired information.

$ apt-get -s dist-upgrade | sed -r -n -e "s/^Inst (.*) \[(.*)\] \((.*) .* \[(.*)\]\).*/\1 \2 \3 \4/p" | sort | awk -F\  '{ printf "%7s\t%-25s %25s -> %-25s\n", $4, $1, $2, $3 }'
  amd64 bind9-host                   1:9.8.4.dfsg.P1-6+nmu2 -> 1:9.8.4.dfsg.P1-6+nmu2+deb7u1
  amd64 dnsutils                     1:9.8.4.dfsg.P1-6+nmu2 -> 1:9.8.4.dfsg.P1-6+nmu2+deb7u1
    all host                         1:9.8.4.dfsg.P1-6+nmu2 -> 1:9.8.4.dfsg.P1-6+nmu2+deb7u1
  amd64 icedtea-6-jre-cacao                   6b27-1.12.5-1 -> 6b27-1.12.6-1~deb7u1
  amd64 icedtea-6-jre-jamvm                   6b27-1.12.5-1 -> 6b27-1.12.6-1~deb7u1
  amd64 icedtea-7-jre-jamvm                     7u3-2.1.7-1 -> 7u25-2.3.10-1~deb7u1
  amd64 libbind9-80                  1:9.8.4.dfsg.P1-6+nmu2 -> 1:9.8.4.dfsg.P1-6+nmu2+deb7u1
  amd64 libdns88                     1:9.8.4.dfsg.P1-6+nmu2 -> 1:9.8.4.dfsg.P1-6+nmu2+deb7u1
  amd64 libisc84                     1:9.8.4.dfsg.P1-6+nmu2 -> 1:9.8.4.dfsg.P1-6+nmu2+deb7u1
  amd64 libisccc80                   1:9.8.4.dfsg.P1-6+nmu2 -> 1:9.8.4.dfsg.P1-6+nmu2+deb7u1
  amd64 libisccfg82                  1:9.8.4.dfsg.P1-6+nmu2 -> 1:9.8.4.dfsg.P1-6+nmu2+deb7u1
  amd64 liblwres80                   1:9.8.4.dfsg.P1-6+nmu2 -> 1:9.8.4.dfsg.P1-6+nmu2+deb7u1
  amd64 openjdk-6-jre-headless                6b27-1.12.5-1 -> 6b27-1.12.6-1~deb7u1
    all openjdk-6-jre-lib                     6b27-1.12.5-1 -> 6b27-1.12.6-1~deb7u1
  amd64 openjdk-6-jre                         6b27-1.12.5-1 -> 6b27-1.12.6-1~deb7u1
  amd64 openjdk-7-jre-headless                  7u3-2.1.7-1 -> 7u25-2.3.10-1~deb7u1
    all openjdk-7-jre-lib                       7u3-2.1.7-1 -> 7u25-2.3.10-1~deb7u1
  amd64 openjdk-7-jre                           7u3-2.1.7-1 -> 7u25-2.3.10-1~deb7u1
Notice that you do not need root privileges.

Update

Over time I have upgraded it to deal with multiple Ubuntu repositories.

[...]
Inst spice-vdagent [0.19.0-2] (0.19.0-2ubuntu0.2 Ubuntu:20.04/focal-updates, Ubuntu:20.04/focal-security [amd64])
[...]
$ apt-get -s dist-upgrade | sed -r -n -e "s/^Inst (.) [(.)] (([a-Z0-9+-:.]) . [(.)])./\1 \2 \3 \4/p" | sort | awk -F\ '{ printf "%7s\t%-25s %25s -> %-25s\n", $4, $1, $2, $3 }'
[...]
amd64 samba-libs 2:4.11.6+dfsg-0ubuntu1.5 -> 2:4.11.6+dfsg-0ubuntu1.6
amd64 slack-desktop 4.10.3 -> 4.11.0
amd64 snapd 2.46.1+20.04 -> 2.47.1+20.04
amd64 spice-vdagent 0.19.0-2 -> 0.19.0-2ubuntu0.2
amd64 systemd 245.4-4ubuntu3.2 -> 245.4-4ubuntu3.3
amd64 systemd-container 245.4-4ubuntu3.2 -> 245.4-4ubuntu3.3
amd64 systemd-sysv 245.4-4ubuntu3.2 -> 245.4-4ubuntu3.3
[...]