I want to get the list of installed packages to perform a fresh installation.

There are many ways of getting these e.g. https://wiki.debian.org/ListInstalledPackages but all produce impractically long lists including dependencies and system packages.

How can I get a list of user installed packages?


All actions performed by apt are logged in /var/log/apt/ but this too has excessive detail and many logs are compressed.

The following script produces a list of actions and the dates on which they were performed.

# Print apt-get history
# 2020-10-07    Include packages installed by packagekit
for logf in $(ls /var/log/apt/history.log.*.gz | sort -rV) ; do zcat $logf | grep -E -A 1 "Start-Date:|Commandline:" | sed -e '/Requested-By:/d' ; done
# Include most recent# grep -E "Start-Date:|Commandline:" /var/log/apt/history.log
grep -E  -A 1  "Start-Date:|Commandline:" /var/log/apt/history.log | sed -e '/Requested-By:/d'

This produces a more manageable list which is easily edited to remove the many "apt upgrade' etc and leave a simple list - the following is an extract:-

Commandline: apt upgrade
Start-Date: 2018-10-24  17:55:57
Commandline: apt install sysbench
Start-Date: 2018-10-29  16:09:33
Commandline: apt-get install --reinstall ssmtp
Start-Date: 2018-10-31  10:23:12
Commandline: apt upgrade
Start-Date: 2018-11-05  17:43:45
Commandline: apt upgrade
Start-Date: 2018-11-05  19:06:56
Commandline: apt purge phpmyadmin
Start-Date: 2018-11-17  10:16:44
Commandline: apt dist-upgrade
Start-Date: 2018-11-17  14:33:07
Commandline: packagekit role='remove-packages'

There are some limitations;

  1. only the last 12 months are shown (because the logs are rotated monthly and only the 12 most recent are kept) but this can be extended by editing /etc/logrotate.d/apt
  2. The Recommended Software program does not list packages added/removed - just a cryptic packagekit role='remove-packages' although the full log does show what was done.

The following script gets history and filters to show User history, excluding updates.

#! /bin/sh
# 2020-10-07    Include packages installed by packagekit
# delete lines containing 'apt upgrade' and preceding line
# useful for finding apt history EXCEPT for upgrades
# run on output of apthist.sh

cat $1 | tac | sed -e '/^--/d' -e '/apt .*upgrade/{N;d;}' | tac

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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