Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I am using apt-get, and often times when I login via ssh I get a statement that:

X upgraded, Y newly installed, Z to remove and A not upgraded.

(Obviously X, Y, Z, A are replaced with the relevant numbers).

Is there a place or a file where these are kept? The shell seems to know when I login, and I scoured the motd files to no avail.

Is there anything on the system that I can get to in order to determine if the machine has an update waiting?

The context for the request: I want to use it as an exercise to modify my powerline-shell and I don't want to do something taxing, since the prompt call needs to stay fast-moving. If those variables can be found and are >0 then I am good to go.

share|improve this question

I don't know of a file that it keeps that information in, but this may interest you:

sudo apt-get dist-upgrade -s | grep "not\ upgraded"

This will print:

1 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

You can continue to get these down to what you want using the cut command:

sudo apt-get dist-upgrade -s | grep "not\ upgraded" | cut -c 1-1"

This will give you just 1, or the first character in that sequence. If this does not equal 0, then you have updates! Simple as that, you can continue expanding to put the following in a script in /usr/bin :

NUMUPG=`sudo apt-get dist-upgrade -s | grep "not\ upgraded" | cut -c 1-1`
if [[ "$NUMUPG" == "0" ]]
then echo "SYSTEM UP-TO-DATE"
  else echo "SYSTEM OUT-OF-DATE"
exit 0

If you create the script, be sure to do chmod +x [FILENAME] before attempting to run it.

Hope that helps! If it does, +1 me!

share|improve this answer
I'm trying to avoid using something that will cause a delay, since the prompt is "rerun" in python every time you hit a new line. I use something similar to your proposal in conky, but I am looking for something quicker. Also trying to avoid using cron to write a separate file. – chow Mar 3 '14 at 1:20
@chow, then you can apply a little more scripting to test if it has been run in the last x minutes already, and skip it if it has. – psusi Mar 3 '14 at 2:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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