How to get the list of installed packages without dependencies?

This doesn't answer the question exactly: it rather gives a command to list all the apt-get install commands ever run along with some advices on how to parse the list further in order to get a list of all the apt-get install command ever run excluding those run by Ubiquity, since the perfect solution for this task seems to not exist.

zcat /var/log/apt/history.log.*.gz | cat - /var/log/apt/history.log | grep -Po '^Commandline:(?= apt-get)(?=.* install ) \K.*'
  • zcat /var/log/apt/history.log.*.gz: decompresses all the compressed apt logs in /var/log/apt, concatenates them and prints to stdout;
  • cat - /var/log/apt/history.log: appends /var/log/apt/history.log and prints to stdout;
  • grep -Po '^Commandline:(?= apt-get)(?=.* install ) \K.*': selects only the lines starting with Commandline: apt-get containing install with a leading and trailing space and prints the remainder of each selected line to stdout;

This will output the list of all the apt-get install commands ever run (the only undesidered output could be an apt-get-non-install command mentioning an install package, but that package doesn't exist (yet?), at least in the default repositories);

Note: In my installation (Ubuntu 15.04 64-bit), the first four commands listed are those run by Ubiquity during the installation; to exclude these, you may pipe the output to sed:

sed '1,4d'

So that the final approximate command for Ubuntu 15.04 64-bit would be:

zcat /var/log/apt/history.log.*.gz | cat - /var/log/apt/history.log | grep -Po '^Commandline:(?= apt-get)(?=.* install ) \K.*' | sed '1,4d'

apt-mark showmanual

will give you a list of all manually installed packages without the dependencies - the important thing to take note of is that it will also show what package were installed during Ubuntu setup.

To write the output to a file:

apt-mark showmanual > somefile

There are actually many other ways, such as using this command

comm -23 <(apt-mark showmanual | sort -u) <(gzip -dc /var/log/installer/initial-status.gz | sed -n 's/^Package: //p' | sort -u) 

Although I have absolutely no idea how the above works ;)

To view packages installed by date:

Packages installed by date use cat /var/log/dpkg.log | grep "\ install\ > somefile"
Packages installed using dpkg use ls -l /var/log/dpkg* > somefile - this one is probably what you're looking for.

To view packages installed using dpkg:

This file contains the above information: /var/log/dpkg.log


This is actually more complicated than it seems, and there are quite a few similar questions on Ask Ubuntu.

I've found that looking in /var/log/apt/history.log and the older gzipped versions of that log, any thing installed by an apt-get install command is listed as installed by that command.

So:

grep "apt-get install" /var/log/apt/history.log

Will show you all of them for the period that the current apt history log covers. You'll need to gunzip your older logs, and grep those to get all of your information together. The grep commands could all be redirected into a text file to give you a nice list.

This is probably only useful for your case if Software Center uses apt-get install when installing. I know that Software Center is a front end for apt but not sure it uses that command explicitly.