I want to get a list of packages that I have installed using apt-get
.
i.e. any packages that I have installed since my Linode (Debian) was initially created.
Is this possible?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityYou can list installed package using apt
using the following command:
apt --installed list
Edit
Use the following command to list installed package through apt-get
:
zcat /var/log/apt/history.log.*.gz | cat - /var/log/apt/history.log | grep -Po '^Commandline: apt-get install (?!.*--reinstall)\K.*'
apt-get
commands.
Jun 6, 2016 at 18:49
(zcat $(ls -tr /var/log/apt/history.log*.gz); cat /var/log/apt/history.log) 2>/dev/null | egrep '^(Commandline: apt(-get)? install)' | grep -v aptdaemon | egrep '^Commandline:'
zgrep -hPo '^Commandline: apt-get install (?!.*--reinstall)\K.*' /var/log/apt/history.log{.*.gz,}
produces the same output without the unnecessary zcat
and cat
. if you don't care about the exact order of package names in the output, /var/log/apt/history.log*
will do for the filename argument.
If you want to display only a list with the packages you have manually installed you could run:
apt --installed list | grep -v automatic
to not list packages flagged as automatically installed
-v, --invert-match Invert the sense of matching, to select non-matching lines.
Another option that won't erroneously exclude an unfortunate package with "automatic" in its name is:
apt-mark showmanual
zgrep -h ' install ' /var/log/dpkg.log* | sort | awk '{print $4}'
This will give you a list of packages that have been installed, in the order that they were installed.
As per my comment, only the last 12 months worth of/var/log/dpkg.log*
files are kept by default. To change this, edit /etc/logrotate.d/dpkg
. For example, change rotate 12
to rotate 1200
to keep the last 1200 months (100 years) worth - effectively forever, never delete the old logs.
BTW, if you want to see when packages were upgraded, change install
to upgrade
. e.g.
zgrep -h ' upgrade ' /var/log/dpkg.log* | sort
same for remove
and purge
.
This relies on aptitude
, but the following will give you a list of packages that are manually installed, i.e. aren't installed just because of dependency:
aptitude search -F %p '~i!~M'
Depending on how the image is setup, it will probably also include some installed by the base system. You can get rid of a fair bit of those by switching them to being automatically installed, then just mark as manual the few you want to keep despite not having anything depending on them. This is easy to do with M inside aptitude
on a bare system.
Use dpkg
to list all packages installed on a system: dpkg --get-selections
To list all packages installed using apt-get
look at /var/log/apt/history.log
. This log also contains packages you have removed. You can grep
for the lines that start with Install:
.
apt-get
commands.
Jun 6, 2016 at 18:45
apt-get
has that functionality. But whenever you install something, it is appended to the log file I mention in the answer.
/var/log/apt/history.log*
files and print out the package names in one hit?
Jun 6, 2016 at 18:51
grep
. grep "Install: package" /var/log/apt/history.log*
Ubuntu 14.04 and above use apt list --installed
for older versions use dpkg --get-selections | grep -v deinstall
A bit shorter and sorted
gunzip -c /var/log/apt/history.log.*.gz | grep 'apt-get install' | cut -f4- -d" " | tr ' ' $'\n' | sort -u
zgrep -Pho '(?<=apt-get install ).*' /var/log/apt/history.log.*.gz | tr ' ' $'\n' | sort -u
.
history.log
files in/var/log/apt/
. It's important to note that, by default, logrotate is configured to keep only the last 12 months worth of these files. The same is true ofthe /dpkg.log
files in/var/log
(which provide similar infomation in an (IMO) more-easily parsed format). Edit/etc/logrotate.d/{apt,dpkg}
to change retention policy for your system.