11

How can I output a list of all installed packages with installation date and additional information?

3 Answers3

19

Open Terminal and run:

zgrep 'install ' /var/log/dpkg.log* | sort | cut -f1,2,4 -d' '

Example output:

2018-09-02 16:10:59 python3-psutil:amd64
2018-09-02 16:11:00 menulibre:all
2018-09-07 14:58:58 indicator-stickynotes:all
2018-09-08 00:17:41 libdumbnet1:amd64
2018-09-08 00:17:41 libxmlsec1-openssl:amd64
...

Since this command will look up into all logs thus the output can be very big. So, it's better to save it into file using

zgrep 'install ' /var/log/dpkg.log* | sort | cut -f1,2,4 -d' ' > test.txt
muru
  • 197,895
  • 55
  • 485
  • 740
Kulfy
  • 17,696
3

Here is a script that uses the files /var/log/dpkg.log* to construct a list of currently installed packages together with the most recent installation date.

#!/bin/bash

LOGDIR=$(mktemp -d)
cd $LOGDIR
cp /var/log/dpkg.log* .

# grep the relevant lines from the log files
for file in dpkg.log*
do
  zgrep ' install ' "$file" > ins.${file%.gz}
done

# Merge all the install lines chronologically into a single file
cat $(ls -rv ins.*) > install.log

# Construct a list of all installed packages in the format packagename:arch
dpkg -l | grep '^.i' | tr -s ' ' | cut -d' ' -f2,4 | tr ' ' : | cut -d: -f1,2 > installed.list

OUTFILE=$(mktemp -p .)

for package in $(< installed.list)
do
  # Get only the most recent installation of the respective package
  grep " $package" install.log | tail -n1 >> "$OUTFILE"
done

sort "$OUTFILE" > newest-installs.log
echo "List of installed packages written to ${LOGDIR}/newest-installs.log"
  • 1
    Maybe try with a here-string construction. Might be faster, eg if grep 'install ' <<< "$line". Also all lines that don't match 'install ' in the if test are remove or purge if the initial grep was done right; so you can if..else instead. Which again should be faster. Any reason to gunzip instead of using zgrep? – pbhj Oct 28 '18 at 22:21
  • 1
    @pbhj: Thanks! However, I noticed that the script didn't really work, due to packages that didn't have a remove line, even though they are uninstalled (those were packages that were probably used temporarily during the installation of Ubuntu). Other packages had duplicate install lines. – Stefan Hamcke Oct 30 '18 at 19:36
  • @pbhj: And I had not used zgrep simply because I wasn't aware of such a command :-) It's good you mentioned it. – Stefan Hamcke Oct 30 '18 at 21:01
2

Use

tail -f /var/log/dpkg.log

or

less /var/log/dpkg.log

or

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

can use grep for a particular package (example)

grep -E 'install .*<package-name>' /var/log/dpkg.log*
Vijay
  • 8,056