16

currently I use this to count the number of available updates

NUMOFUPDATES=$(aptitude search "~U" | wc -l)

Is there a way to do the same with apt(not aptitude) but not using the update-notifier?

net cat
  • 211

4 Answers4

19

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.

jnas
  • 468
6

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
Eliah Kagan
  • 119,640
1

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

rubo77
  • 34,024
  • 52
  • 172
  • 299
-1

I just run the command:

sudo apt-get update && sudo apt-get upgrade

After performing the update process, it gives the output for upgrade command as:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be upgraded:
  wine1.5 wine1.5-i386
2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 24.1 MB of archives.
After this operation, 286 kB of additional disk space will be used.
Do you want to continue [Y/n]?

The 6th line mentions that there are 2 upgrades available and the 5th line lists the packages for which the upgrades are available. If I not in the mood to install the upgrades right at that moment I press n and move on.

Straight and simple.

Note: If there are kernal updates available as well, it would show them as <x> not upgraded.

Aditya
  • 13,616