apt-get count the number of updates available
You could use apt-check
from update-notifier-common
:
$ /usr/lib/update-notifier/apt-check --human-readable
0 packages can be updated.
0 updates are security updates.
This is the same tool that updates the motd
message.
I suppose the fastest method is shown in apticron:
https://salsa.debian.org/debian/apticron/blob/master/apticron#L121-154
This can be distilled to:
apt-get -q -y --ignore-hold --allow-change-held-packages --allow-unauthenticated -s dist-upgrade | /bin/grep ^Inst | wc -l
You can use apt-get -s
to simulate an upgrade process and extract only the number of upgraded packages by
LANG=C apt-get upgrade -s |grep -P '^\d+ upgraded'|cut -d" " -f1
This will result in just the number of packages