How to know last time `apt-get update` was executed?

I know that the command to update the repository lists is:

apt-get update

How to check if it has been executed today or in the last 24 hours?

I do not know if I should check some file timestamp. Or issue another apt command. Or use dpkg utility.

Could not find something useful at man pages.


Check the time stamp of /var/lib/apt/periodic/update-success-stamp.

$ ls -l /var/lib/apt/periodic/update-success-stamp
-rw-r--r-- 1 root root 0 Jan 25 01:41 /var/lib/apt/periodic/update-success-stamp

Here the time is Jan 25 01:41 when apt-get last executed. To get the time only, use the following command in terminal,

$ ls -l /var/lib/apt/periodic/update-success-stamp | awk '{print $6" "$7" "$8}'
Jan 25 01:41

It is the best place to check the last update time. If you found /var/lib/apt/periodic/ to be empty you can try,

ls -l /var/log/apt/history.log

Update

It is found that due to some reasons above files update-success-stamp or history.log remain unavailable in some systems. There is a new proposal from derobert to look into the file /var/cache/apt/pkgcache.bin.

pkgcache.bin is Apt's memory mapped package cache location. It get renewed after each update. So it is the perfect candidate to know the last time when apt was updated.

One can use the following command to know the exact time,

ls -l /var/cache/apt/pkgcache.bin | cut -d' ' -f6,7,8

or

stat /var/cache/apt/pkgcache.bin

You can check your command history in terminal :

history | grep 'apt update'

To check it by time :

HISTTIMEFORMAT="%d/%m/%y %T " history | grep '[a]pt update'

(The [a] part of the regular expression only matches the letter a but has the effect to not match itself when grepping in the history.)

Terminal history with timestamp