3

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)

Sam
  • 43
  • You can always look at /var/log/dpkg.log* or do some dpkg -L the-package | xargs -rd '\n' ls -lrtcd | grep '^-' – Stéphane Chazelas Aug 08 '22 at 10:41
  • Appreciated, but unfortunately that returned the wrong date (maybe date created instead of date modified? Not sure). – Sam Aug 08 '22 at 10:47
  • the ctime (change status time, not creation time) as reported by ls -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:48
  • I wasn't suggesting the output is lying - I was saying the date returned doesn't match the last package update date. Maybe you're making an assumption that every package update will change status on files matching the search pattern? – Sam Aug 08 '22 at 10:57
  • except maybe for virtual packages, an update would unpack the data with the new version of the files, so for files that are not otherwise touched after install, you'll see the unpacking time. – Stéphane Chazelas Aug 08 '22 at 11:23
  • You certainly seem to know what you're talking about, but all I can tell you is there's a two-year discrepancy between the date on those files and the last xorg update. – Sam Aug 08 '22 at 11:25
  • What package did you check? If that was the xorg package, note that it's just a meta package, with no data coming with it. – Stéphane Chazelas Aug 08 '22 at 11:28
  • That's probably it - I didn't exactly specify in the question (but alluded to) not wanting to need the specific package name where something could consist of several packages. So was hoping I could just search "xorg", safe in the knowledge that string would be contained in the package name. – Sam Aug 08 '22 at 11:30

1 Answers1

5

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

Stephen Kitt
  • 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
  • Yes, all package updates involve dpkg. – Stephen Kitt 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
  • Many thanks :-) – Sam 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
  • Bash doesn't like that one. Is there a more shell-agnostic form? – Sam Aug 08 '22 at 10:58
  • 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 avoids zcat 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