Just the code
aptitude search '~i !~M' -F '%p' --disable-columns | sort -u > currentlyinstalled.txt
wget -qO - http://mirror.pnl.gov/releases/precise/ubuntu-12.04.3-desktop-amd64.manifest \
| cut -f1 | sort -u > defaultinstalled.txt
comm -23 currentlyinstalled.txt defaultinstalled.txt
Explanation
One way to think about this problem is to break this into three parts:
- How do I get a list of packages not installed as dependencies?
- How do I get a list of the packages installed by default?
- How can I get the difference between these two lists?
How do I get a list of packages not installed as dependencies?
The following command seems to work on my system:
$ aptitude search '~i !~M' -F '%p' --disable-columns | sort -u > currentlyinstalled.txt
Similar approaches can be found in the links that Gilles posted as a comment to the question. Some sources claim that this will only work if you used aptitude to install the packages; however, I almost never use aptitude to install packages and found that this still worked. The --disable-columns
prevents aptitude from padding lines of package names with blanks that would hinder the comparison below. The | sort -u
sorts the file and removes duplicates. This makes the final step much easier.
How do I get a list of the packages installed by default?
Note: This section starts out with a 'wrong path' that I think is illustrative. The second piece of code is the one that works.
This is a bit trickier. I initially thought that a good approximation would be all of the packages that are dependencies of the meta-packages ubuntu-minimal, ubuntu-standard, ubuntu-desktop, and the various linux kernel related packages. A few results on google searches seemed to use this approach. To get a list of these dependencies, I first tried the following (which didn't work):
$ apt-cache depends ubuntu-desktop ubuntu-minimal ubuntu-standard linux-* | awk '/Depends:/ {print $2}' | sort -u
This seems to leave out some packages that I know had to come by default. I still believe that this method should work if one constructs the right list of metapackages.
However, it seems that Ubuntu mirrors contain a "manifest" file that contains all of the packages in the default install. The manifest for Ubuntu 12.04.3 is here:
http://mirror.pnl.gov/releases/precise/ubuntu-12.04.3-desktop-amd64.manifest
If you search through this page (or the page of a mirror closer to you):
http://mirror.pnl.gov/releases/precise/
You should be able to find the ".manifest" file that corresponds to the version and architecture you are using. To extract just the package names I did this:
wget -qO - http://mirror.pnl.gov/releases/precise/ubuntu-12.04.3-desktop-amd64.manifest | cut -f1 | sort -u > defaultinstalled.txt
The list was likely already sorted and unique, but I wanted to be sure it was properly sorted to make the next step easier. I then put the output in defaultinstalled.txt
.
How can I get the difference between these two lists?
This is the easiest part since most Unix-like systems have many tools to do this. The comm
tool is one of many ways to do this:
comm -23 currentlyinstalled.txt defaultinstalled.txt
This should print the list of lines that are unique to the first file. Thus, it should print a list of installed packages not in the default install.
aptitude search '~i!~M' -F %p
doesn't? – ephemient Oct 30 '10 at 04:57| sed "s/ *$//"
to the pipeline. – Emil Styrke May 23 '14 at 17:38http://releases.ubuntu.com/releases/trusty/ubuntu-14.04-desktop-amd64.manifest
and the additional| sed "s/ *$//"
but still no dice. – jmiserez Jul 06 '14 at 14:14sed
and the correct manifest file for my system. – jmiserez Jul 08 '14 at 13:06Some sources claim that this will only work if you used aptitude to install the packages; however, I almost never use aptitude to install packages and found that this still worked.
that's because that hasn't been true for several years now. It used to be the case that aptitude and apt-get used different databases to record which packages were installed automatically but this has not been the case for a number of stable Debian versions ie many years. Old advice tends to stick around after it's no longer true. – trr Oct 22 '14 at 08:36apt-mark showmanual | sort -u
, as shown in other answers. Simpler, and does not rely onaptitude
which is not installed by default. – skagedal May 03 '15 at 06:44wget -qO - https://releases.ubuntu.com/$(grep -oP 'VERSION_CODENAME=\K.+' /etc/os-release)/ubuntu-$(grep -oP 'VERSION= "\K[0-9\.]+' /etc/os-release)-desktop-amd64.manifest | cut -f1 | cut -d: -f1 | sort -u > defaultinstalled.txt
(replace theamd64
as needed). – Tyn Apr 08 '20 at 07:17VERSION=
needs to be removed).Otherwise, convenient one-liner:
– Tyn Apr 08 '20 at 07:28comm -23 <(apt-mark showmanual | sort -u) <(curl -s -- https://releases.ubuntu.com/$(grep -oP 'VERSION_CODENAME=\K.+'/etc/os-release)/ubuntu-$(grep -oP 'VERSION="\K[0-9\.]+' /etc/os-release)-desktop-amd64.manifest | cut -f1 | cut -d: -f1 | sort -u)