7

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

0
11

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
5
  • 1
    That will show packages that have been removed too.
    – pbhj
    Oct 28 '18 at 13:12
  • 1
    This only looks in one log file dpkg.log.1 - could be improved to zgrep in all the log files. But a good start, +1 Oct 28 '18 at 15:47
  • 1
    zgrep 'install ' /var/log/dpkg.log* | sort | cut -f1,2,4 -d' ' > test.txt Oct 28 '18 at 15:52
  • 1
    You are correct, modify as you like. If you pull in all the log files, you get a lot of output. Oct 28 '18 at 15:56
  • $ cat /var/log/dpkg.log | grep '2020-01-05'. YYYY-MM-DD
    – noobninja
    Jan 5 '20 at 8:36
2

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"
3
  • 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. 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. Oct 30 '18 at 21:01
1

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*

Not the answer you're looking for? Browse other questions tagged or ask your own question.