4

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?

1 Answer 1

3

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.

I have modified my apthist script to show only user installed packages.

#!/bin/bash
#Print apt-get history EXCEPT for upgrades
# 2017-08-06
# 2020-10-07    Include packages installed by packagekit
# 2020-12-04    delete lines containing 'apt upgrade' and preceding line

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 \
  | tac | sed -e '/^--/d' -e '/apt .*upgrade/{N;d;}' | tac

# Include most recent
grep -E  -A 1  "Start-Date:|Commandline:" /var/log/apt/history.log | sed -e '/Requested-By:/d' \
  | tac | sed -e '/^--/d' -e '/apt .*upgrade/{N;d;}' | tac
  1. Below is a script I use to list apt history. This is still handy if you are interested in upgrades.
#!/bin/bash
# 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'

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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