13

I am trying to get package name with version, splitted package and version, vendor of that package, install time and date using:

dpkg-query -W -f='${Package}-${version} ${package} ${version} ${Maintainer} ${installtime}\n'

But I got package name with version, splitted package and version, vendor of that package. I was not able to retrieve install time and date.

How can I get package install time and date with the above query?

heemayl
  • 94,145
KISHORE
  • 131

5 Answers5

8

dpkg-query does not have any field option to show date/time of installation. The other way of saying this is that dpkg does not store this information. Under the hood, dpkg-query uses various files in /var/lib/dpkg/ to get the information.

Here are the available field names:

Architecture
Bugs
Conffiles (internal)
Config-Version (internal)
Conflicts
Breaks
Depends
Description
Enhances
Essential
Filename (internal, front-end related)
Homepage
Installed-Size
MD5sum (internal, front-end related)
MSDOS-Filename (internal, front-end related)
Maintainer
Origin
Package
Pre-Depends
Priority
Provides
Recommends
Replaces
Revision (obsolete)
Section
Size (internal, front-end related)
Source
Status (internal)
Suggests
Tag (usually not in .deb but in repository Packages files)
Triggers-Awaited (internal)
Triggers-Pending (internal)
Version

And some virtual fields too:

binary:Package
binary:Summary
db:Status-Abbrev
source:Package
source:Version

Check man dpkg-query to get a broader idea.


Note that, you can look at /var/log/dpkg.log* for the installation date/time of packages. Also note that, if your package is installed by apt-get (or brothers), you can look at the apt history files, /var/log/apt/history.log*, too.

heemayl
  • 94,145
  • ok.. I tried to use below command. locate dpkg.log | xargs cat {} | grep "install" | awk '{print $5$6, $5,$6,$2,$1}'. Here i got package name with version, splitted package, version, Install time and date. Not able to get vendor details. Could you please let me know how i will get vendor details with the command. – KISHORE Jun 23 '16 at 23:06
  • @KISHORE what do you mean by vendor details? – heemayl Jun 24 '16 at 09:58
1

I use:

sudo dpkg-query -f '${binary:Package}\n' -W > packages_list.txt
Eliah Kagan
  • 119,820
Jackspace
  • 133
1

For Ubuntu you can copy the approach from Debian:

root@stuff:~# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 12 (bookworm)
Release:        12
Codename:       bookworm
root@stuff:~# type pkglist 
pkglist is a function
pkglist () 
{ 
    dpkg-query -W -f='${Package} ${db-fsys:Last-Modified}\n' | sort -k2,2nr | awk '{printf("%-32s %s\n", $1,strftime("%c",$2))}'
}

So add the following lines to the end of your .bashrc in your home directory:

# Adding function to query update times of packages
pkglist () 
{  
    dpkg-query -W -f='${Package} ${db-fsys:Last-Modified}\n' | sort -k2,2nr | awk '{printf("%-32s %s\n", $1,strftime("%c",$2))}'
}

Then do source .bashrc.
After that, you can get the list of installed packages with pkglist:

root@stuff:~# pkglist | head
libglib2.0-data                  Thu May 23 11:10:41 2024
libglib2.0-0                     Thu May 23 11:10:38 2024
locales                          Thu May 23 11:10:36 2024
libc-l10n                        Thu May 23 11:10:31 2024
less                             Thu May 23 11:10:29 2024
libc-bin                         Thu May 23 11:10:25 2024
libc6                            Thu May 23 11:10:05 2024
linux-image-6.1.0-17-686-pae     Sat Apr 27 14:46:31 2024
util-linux-locales               Wed Apr 24 07:44:37 2024
linux-image-686-pae              Wed Apr 24 07:44:35 2024
zx485
  • 2,894
0

It works, but i think it is too slow.

function lspkgs {
    local installation_text=$(grep " install " /var/log/dpkg.log*)
    for i in $(dpkg-query -f='${Package}\n' -W); do
        echo $(dpkg-query -f='${Package}-${version} ${package} ${version} ${Maintainer} ${installtime}\n' -W $i) $(echo "$installation_text" | grep " install $i:" | sort -n | tail -n1 | cut -d' ' -f 1,2)
    done
}

The output of lspkgs command.

adduser-3.118 adduser 3.118 Debian Adduser Developers <adduser@packages.debian.org> 2022-09-09 03:16:59
alsa-topology-conf-1.2.4-1 alsa-topology-conf 1.2.4-1 Debian ALSA Maintainers <pkg-alsa-devel@lists.alioth.debian.org> 2022-09-09 11:46:40
alsa-ucm-conf-1.2.4-2 alsa-ucm-conf 1.2.4-2 Debian ALSA Maintainers <pkg-alsa-devel@lists.alioth.debian.org> 2022-09-09 11:46:42
anacron-2.3-30 anacron 2.3-30 Debian QA Group <packages@qa.debian.org> 2022-09-09 11:46:44
0

You can also run below command as show in Screenshot reference.

ls -ltr /var/cache/apt/archives/*.deb 

enter image description here

Mr. Linux
  • 195