Getting a list of recently installed packages in Ubuntu

Summary Want to know what's recently been installed on your system? It's as simple as a few commands.

It's sometimes handy to see a list of recently installed packages, so that you can remember what you were fiddling with.

$ cat /var/log/dpkg.log* | grep "\ install\ " | sort

This does a few things:

  • First, we concatenate all of the package logs from dpkg, the package manager for Debian. The package logs will have names like /var/log/dpkg.log.1, /var/log/dpkg.log.2, and so on. (The oldest logs will be zipped up, using Ubuntu's built-in log rotation, so they will look like /var/log/dpkg.log.3.tar.gz.)
  • This is then piped to grep so that we find only installation events. Specifically, we look only for lines that contain a space, followed by the word "install", followed by another space.
  • Finally, we sort the list of items we got. Because each dpkg record line begins with a timestamp, items that were installed earlier will be sorted first in this list.

The result is a chronological list of package installation events, with the most recently installed package first. (Note that if a package was installed and subsequently removed, it will still be on the list.)

If you want to get some subset with the most recently installed one first, you can use a combination of sort -r and head -n. For example:

# Retrieve the last 5 most recently installed packages, with
# the most recently installed one first.
$ cat /var/log/dpkg.log* | grep "\ install\ " | sort -r | head -n 5
2009-06-20 23:47:49 install easytag <none> 2.1.4-1.1
2009-06-20 23:47:49 install libid3-3.8.3c2a <none> 3.8.3-7.2
2009-06-19 18:08:02 install wv <none> 1.2.4-2ubuntu2
2009-06-19 18:08:01 install tracker-utils <none> 0.6.93-0ubuntu3
2009-06-19 18:08:01 install tracker-search-tool <none> 0.6.93-0ubuntu3

Update: Commenter maximd noted that you can also bring zcat into the equation to get an even more comprehensive list that will introspect the log files. This will hit the older logs that have been zipped up, so you can go farther back if needed.

Trackbacks (none)

TrackBack URL: http://distilledb.com/mt/mt-tb.cgi/61

Comments (9)

Many thanks. This really worked. Thank you. Great stuff.

You are most welcome! :)

Thanks -- very helpful!

If you want to have a more comprehensive history of the installed packages, you can also use:

zcat /var/log/dpkg.log* | grep "\ install\ " | sort

With zcat, the dpkg.log.*.gz can be analyzed too.

In fact a little modification is needed to be able to read non-gzipped dpkg logs:

zcat -f /var/log/dpkg.log* | grep "\ install\ " | sort

Note the -f ("force") option which lets zcat behave as cat.

Sorry for the confusion.

Bookmarked !

How to install debian packages? Somebody remove my dpkg and synaptic pack manager...! How i get synaptic manager?

Thanks -- very helpful! great work............ This really worked. Thank you. Great stuff.

Thank you, this was very helpful. It was also enlightening to analyze the script to understand what it means for writing future scripts.

leave new comment