Is there a command that will return the date and time of the last update to a specific package? Currently I'm interested in the last time my xorg was updated (I know, some software will consist of more than one package) but it's something I've often wanted to know about various packages. I'm running Linux Mint. (and yes I know there's an update history GUI feature in Mint but it's a load of scrolling and potential for human error)
1 Answers
For a specific package,
zgrep -h "status installed package" /var/log/dpkg.log* | sort | tail -n 1
will tell you the last time the package was successfully installed (which reflect the package state, so it also includes upgrades). Since dpkg
is involved in all package operations in Debian derivatives, this will work regardless of which package management tool is used (dpkg
directly, apt
, PackageKit etc.).
For example,
$ zgrep -h "status installed xserver-xorg-core" /var/log/dpkg.log* | sort | tail -n 1
2022-08-07 06:40:54 status installed xserver-xorg-core:amd64 2:1.20.11-1+deb11u2
If apt
is involved (which is usually the case, except when dpkg
is used directly), you can get more information from its history:
zcat -f $(ls -tr /var/log/apt/history.log*)|awk -v RS= '/package/{s=$0}; END{print s}'
This will tell you when the package was last involved in an apt
operation, and the command that affected it. For example:
$ zcat -f $(ls -tr /var/log/apt/history.log*)|awk -v RS= '/xserver-xorg-core/{s=$0}; END{print s}'
Start-Date: 2022-08-07 06:40:51
Commandline: /usr/bin/unattended-upgrade
Upgrade: xserver-xorg-core:amd64 (2:1.20.11-1+deb11u1, 2:1.20.11-1+deb11u2)
End-Date: 2022-08-07 06:41:01
(I’m aware of Why *not* parse `ls` (and what to do instead)? I’m assuming the file names are safe here, which is the case in a default setup with the default log rotation. I’m also assuming that IFS
is set to its default value.)
The top-most entry in a package’s changelog.Debian.gz
file will tell you when it was last modified in your distribution:
$ zcat /usr/share/doc/xserver-xorg-core/changelog.Debian.gz | head -n 7
xorg-server (2:1.20.11-1+deb11u2) bullseye-security; urgency=medium
- xkb: add request length validation for XkbSetGeometry (CVE-2022-2319)
- xkb: swap XkbSetDeviceInfo and XkbSetDeviceInfoCheck (CVE-2022-2320)
- Closes: #1014903.
-- Emilio Pozuelo Monfort <pochu@debian.org> Fri, 05 Aug 2022 10:00:36 +0200

- 434,908
-
Awesome, thank you! Will the dpkg operations one catch all packages updated via the GUI software updater? It did work nicely for xorg (even just using "xorg" instead of the full package name). – Sam Aug 08 '22 at 10:52
-
-
You'd need
zgrep -hB2 package /var/log/apt/history.log*(nOn) | tail -n 3
(assuming zsh) to get the most recent entry. – Stéphane Chazelas Aug 08 '22 at 10:52 -
-
zcat -f /var/log/apt/history.log*(nOn) | awk -v RS= '/package/{s=$0}; END{print s}'
may be better. – Stéphane Chazelas Aug 08 '22 at 10:57 -
-
ls -rvd /var/log/apt/history.log*
would probably be better than relying on modification time. Note that$(...)
invokes split+glob which relies on the current value of$IFS
(here expected to contain newline and none of the characters found in the path of those files). – Stéphane Chazelas Aug 08 '22 at 12:09 -
Note that some
zcat
variants complain if given uncompressed files unless you use-f
. – Stéphane Chazelas Aug 08 '22 at 12:11 -
@Stéphane would this be a case where
xargs
would be better than relying on the shell’s word splitting? – Stephen Kitt Aug 08 '22 at 12:14 -
Using
xargs -rd '\n'
allows specifying the separator and also avoidszcat
seemingly hanging if no log file is found. Newer versions of GNU ls have--zero
, but I doubt it's made its way into any Debian-like OS release yet. – Stéphane Chazelas Aug 08 '22 at 12:20 -
The OP looks like they may actually want the last update date of any package that were built from the
xorg
software (source package?). – Stéphane Chazelas Aug 08 '22 at 12:25 -
I think... yes? I just wanted to know when xorg was last updated. But I might want the same for kernel, graphics drivers or any number of other things. Both the zgrep and latest zcat solutions seem to work nicely though! – Sam Aug 08 '22 at 13:11
/var/log/dpkg.log*
or do somedpkg -L the-package | xargs -rd '\n' ls -lrtcd | grep '^-'
– Stéphane Chazelas Aug 08 '22 at 10:41ls -c
doesn't lie. If it says 2022-06-07 for some file, that file hasn't been touched since. – Stéphane Chazelas Aug 08 '22 at 10:48xorg
package, note that it's just a meta package, with no data coming with it. – Stéphane Chazelas Aug 08 '22 at 11:28