How to see packages installed on a given date using 'aptitude'?

Unfortunately, dpkg (the package handler aptitude works on top of) does not specifically save the install date of packages, although there's thoughts of adding it. However, the install date can be found by looking at the date stamp of files written to the directory /var/lib/dpkg/info.


By default, aptitude writes to a log file /var/log/aptitude. It produces output like this:

===============================================================================

Aptitude 0.8.12: log report
Sun, Oct  1 2021 23:59:59 +1300

  IMPORTANT: this log only lists intended actions; actions which fail
  due to dpkg problems may not be completed.

Will install 6 packages, and remove 0 packages.
31.3 MB of disk space will be used
========================================
[UPGRADE] libc-dev-bin:amd64 2.31-0ubuntu9 -> 2.31-0ubuntu9.2
[UPGRADE] libc6:amd64 2.31-0ubuntu9 -> 2.31-0ubuntu9.2
[UPGRADE] libc6:i386 2.31-0ubuntu9 -> 2.31-0ubuntu9.2
[UPGRADE] libc6-dbg:amd64 2.31-0ubuntu9 -> 2.31-0ubuntu9.2
[UPGRADE] libc6-dev:amd64 2.31-0ubuntu9 -> 2.31-0ubuntu9.2
[UPGRADE] libc6-i386:amd64 2.31-0ubuntu9 -> 2.31-0ubuntu9.2
========================================

Log complete.
===============================================================================

This shows the exact date and packages that aptitude installed. To configure this (in /etc/apt/apt.conf or in a separate file in /etc/apt/apt.conf.d/), follow the Configuration file reference in aptitude manual (also available from "Help > User's Manual" in the menu):

Option:Aptitude::Log

Default:/var/log/aptitude

Description: If this is set to a nonempty string, aptitude will log the package
installations, removals, and upgrades that it performs. If the value of
Aptitude::Log begins with a pipe character (ie, ``|''), the remainder of its
value is used as the name of a command into which the log will be piped: for
instance, |mail -s 'Aptitude install run' root will cause the log to be emailed
to root. To log to multiple files or commands, you may set this option to a list
of log targets.

There is a simple way to see all packages installation date. Just execute:

grep " install" /var/log/dpkg.log*

As a result you will get a list of all installed packages with exact date and time.

Thanks for comments which lead me to that solution.


I found this one here on the web. It creates a history of dpkg out of the dpkg log file.

It looks very simple.

function apt-history(){
      case "$1" in
        install)
              cat /var/log/dpkg.log | grep 'install '
              ;;
        upgrade|remove)
              cat /var/log/dpkg.log | grep $1
              ;;
        rollback)
              cat /var/log/dpkg.log | grep upgrade | \
                  grep "$2" -A10000000 | \
                  grep "$3" -B10000000 | \
                  awk '{print $4"="$5}'
              ;;
        *)
              cat /var/log/dpkg.log
              ;;
      esac
}

Source

EDIT

I tried this script on Ubuntu 8.10 Server and it works very well. Could you provide some information, how you solved your problem?