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?

2
  • Appears to be a duplicate of askubuntu.com/q/49958/20422
    – KayEss
    Commented Apr 6, 2013 at 3:28
  • Your question has just answered mine, because for me aptitude is fine.
    – soger
    Commented Jun 28, 2017 at 11:49

4 Answers 4

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.

0
5

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
2
  • Note the -s near the end, which means `simulate'
    – Tim Bray
    Commented Jan 13, 2022 at 11:55
  • +1 for single integer output, and no extra packages or installs needed. Thanks! this was exactly what I was looking for
    – m1m1k
    Commented Mar 8 at 15:46
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

-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.

6
  • I think the OP wants to retrieve this number in a form that can be used in a script, not just to see it. Commented Mar 18, 2013 at 17:29
  • Thanks, but all I need to get is just the number of updates available, in your example it is "2". Then the script shows notification "Available updates - 2"
    – net cat
    Commented Mar 18, 2013 at 17:30
  • @Eric Carvalho True.
    – net cat
    Commented Mar 18, 2013 at 17:30
  • @netcat: Oh... Don't know the answer then, I thought you just wanted to know how many number of updates are available casually (as I tend to do most often) :-)
    – Aditya
    Commented Mar 18, 2013 at 17:31
  • @netcat: Would python script be okay for you? I might try to script that..
    – Aditya
    Commented Mar 18, 2013 at 17:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .