1. Introduction

Managing software packages is an essential task for system administrators and users who use Linux operating system. Package managers maintain a database record of the available software packages and related metadata such as dependencies, version information, and installation history.

Different Linux distros utilize package managers, such as APT (Advanced Package Tool) for Debian-based systems (including Ubuntu) and YUM (Yellowdog Updater Modified) or DNF (Dandified YUM) for RedHat-based systems (such as Fedora), to handle software installations, updates, and removals.

For system maintenance or troubleshooting, it can be important to keep a sorted list of all current packages on the system.

In this tutorial, we’ll explore methods of listing installed packages in order of the installation date on different Linux distros.

2. On Ubuntu and Other Debian-based Distros

A clear overview of all the installed packages is crucial when managing other Debian-based systems.

Debian-based systems have a dpkg.log file containing a record of various activities related to the Debian package management system. The /var/log/dpkg.log file contains information logged every time a package is installed or removed using the dpkg command.

Each line has information about a specific package, including the date and time, action, package name, and additional details about the operation.

Thus, we can use the dpkg.log file to list all installed packages in order of the installation date:

$ grep " install" /var/log/dpkg.log
2023-08-02 08:57:22 status installed gcc-10-base:amd64 10.5.0-1ubuntu1~20.04
2023-08-02 08:57:23 status installed libstdc++6:amd64 10.5.0-1ubuntu1~20.04
2023-08-02 08:57:29 status installed libgcc-s1:amd64 10.5.0-1ubuntu1~20.04
2023-08-02 08:57:29 status installed libgomp1:amd64 10.5.0-1ubuntu1~20.04
2023-08-02 08:57:29 status installed libquadmath0:amd64 10.5.0-1ubuntu1~20.04
2023-08-02 08:57:29 status installed libatomic1:amd64 10.5.0-1ubuntu1~20.04
2023-08-02 08:57:30 status installed libgfortran5:amd64 10.5.0-1ubuntu1~20.04
...

Using regular expressions, the grep command searches a file for a specific pattern of characters and displays all lines containing a match.

The command above matches all lines containing the phrase “ install” and outputs them in descending order.

Alternatively, we can also view partially installed packages:

$ grep "half-install" /var/log/dpkg.log
2023-08-02 08:57:19 status half-installed libatomic1:amd64 10.3.0-1ubuntu1~20.04
2023-08-02 08:57:20 status half-installed libubsan1:amd64 10.3.0-1ubuntu1~20.04
2023-08-02 08:57:20 status half-installed libtsan0:amd64 10.3.0-1ubuntu1~20.04
...

Log rotation is used in computing and system administration to manage log files.

If log rotation is enabled, we can view the previous install log file:

$ grep " install" /var/log/dpkg.log*
/var/log/dpkg.log:2023-08-08 09:03:42 status installed gnome-menus:amd64 3.36.0-1ubuntu1
/var/log/dpkg.log:2023-08-08 09:03:49 status installed firefox-locale-en:amd64 116.0.2+build1-0ubuntu0.20.04.1
/var/log/dpkg.log.1:2023-07-07 09:16:56 status installed firefox:amd64 115.0+build2-0ubuntu0.20.04.3
/var/log/dpkg.log.1:2023-07-07 09:16:58 status installed man-db:amd64 2.9.1-1
...

We’ve added an asterisk * at the end of this command to match all dpkg.log files. The output above shows matches in both the dpkg.log and the dpkg.log.1 log files.

We can also view all archive log files by including another period before the asterisk and using zgrep:

$ zgrep " install" /var/log/dpkg.log.*
...
/var/log/dpkg.log.1:2023-07-26 06:26:28 status installed linux-image-5.15.0-75-generic:amd64 5.15.0-75.82~20.04.1
/var/log/dpkg.log.1:2023-07-26 06:26:28 status installed linux-modules-5.15.0-75-generic:amd64 5.15.0-75.82~20.04.1
/var/log/dpkg.log.10.gz:2022-10-06 06:51:24 status installed firefox-locale-en:amd64 105.0+build2-0ubuntu0.20.04.1
/var/log/dpkg.log.10.gz:2022-10-06 06:51:34 status installed thunderbird:amd64 1:102.2.2+build1-0ubuntu0.20.04.1
...

The output above shows matching lines in all archive log files.

3. On Arch Linux

Pacman is the default package manager on Arch-based distros. It contains compressed files as packages and maintains a text-based database. Pacman keeps the system up to date by synchronizing the package list. Moreover, we can install packages from official repositories or our own build packages.

We’re going to use the expac command to list the packages. In case it’s not available, we can install it via pacman using the sudo command for root privileges:

$ sudo pacman -S expac

Now, we can employ expac to list installed packages sorted by installation date:

$ expac --timefmt='%Y-%m-%d %T' '%l\t%n' | sort -n
2022-12-15 13:02:09 iana-etc
2022-12-15 13:02:10 filesystem
2023-12-15 13:02:14 glibc
2023-12-15 13:02:20 ncurses
...

In general, the expac command is a data extraction tool for alpm databases. We’re using –timefmt=’%Y-%m-%d %T’ to format the stored date and time. Further, ‘%l\t%n’ lists each package on a different line. Finally, we pipe to sort for numeric-based ordering via -n.

We can also truncate the list to show a specific number of lines:

$ expac --timefmt='%Y-%m-%d %T' '%l\t%n' | sort | tail -n 3
2022-12-15 13:02:09 iana-etc
2022-12-15 13:02:10 filesystem
2023-12-15 13:02:14 glibc

The command above lists the first three lines by adding tail to the pipeline. We can specify the number of lines by changing the number 3 at the end of the command above.

4. On CentOS, Fedora, and Other RHEL-based Distros

RPM is a popular package management utility for RedHat-based distros. It lets system admins and users install, update, uninstall, query, and maintain system software packages. rpm includes compiled software programs and libraries required by packages. The utility only supports packages built in the .rpm format.

Let’s list all installed packages in the order of installation date via rpm:

# rpm -qa --last
syslinux-extlinux-6.04-0.16.fc33.x86_64 Monday 19 October 2022 11:37:47 PM
sudo-1.9.2-1.fc33.x86_64 Wednesday 19 October 2022 11:37:47 PM
rsync-3.2.3-1.fc33.x86_64 Wednesday 19 October 2022 11:37:47 PM
parted-3.3-5.fc33.x86_64 Wednesday 19 October 2022 11:37:47 PM
man-db-2.9.2-6.fc33.x86_64 Wednesday 19 October 2022 11:37:47 PM
...

In this case, we add the -qa options to query all matches of the latest installed packages in descending order.

Alternatively, we can also use the command to list all installed packages in order of installation date:

# rpm -qa --qf '%{INSTALLTIME} (%{INSTALLTIME:date}): %{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' | sort -n

The command above formats the output via special format specifiers and shows the installation date and time, the package name, version, and release date.

We can also view the installation date for a specific package:

# rpm -q --last ncurses
ncurses-4.2.3-1.fc33.x86_64 Wednesday 19 2022 11:37:47 PM

The output above shows the last installation date for ncurses.

5. Conclusion

In this article, we’ve gone through methods of listing installed packages in order of installation date for different Linux distros. We first looked at listing installed packages of Debian-based systems. Then, we did the same on Arch Linux and CentOS, Fedora, and other RHEL-based systems.