You can use either of these two one-liners. Both yield the exact same output on my machine and are more precise than all solutions proposed up until now (July 6, 2014) in this question.
Using apt-mark
:
comm -23 <(apt-mark showmanual | sort -u) <(gzip -dc /var/log/installer/initial-status.gz | sed -n 's/^Package: //p' | sort -u)
Using aptitude
:
comm -23 <(aptitude search '~i !~M' -F '%p' | sed "s/ *$//" | sort -u) <(gzip -dc /var/log/installer/initial-status.gz | sed -n 's/^Package: //p' | sort -u)
Very few packages still fall through the cracks, although I suspect these are actually installed by the user, either right after the installation through the language localization setup or e.g. through the Totem codec installer. Also, the linux-header versions also seem to accumulate, even though I've only installed the non version-specific metapackage. Examples:
libreoffice-help-en-gb
openoffice.org-hyphenation
gstreamer0.10-fluendo-mp3
linux-headers-3.13.0-29
How does it work:
- Get the list of manually installed packages. For aptitude, the additional
sed
strips out remaining whitespace at the end of the line.
- Get the list of packages installed right after a fresh install.
- Compare the files, only output the lines in file 1 that are not present in file 2.
Other possibilities don't work as well:
- Using the
ubuntu-14.04-desktop-amd64.manifest
file (here for Ubuntu 14.04) instead of /var/log/installer/initial-status.gz
. More packages are shown as manually installed even though they are not.
- Using
apt-mark showauto
instead of /var/log/installer/initial-status.gz
. apt-mark
for example doesn't include the xserver-xorg package, while the other file does.
I used various other StackExchange posts as references, however none work as well as the above solution:
Both list more packages than the above solution.
EDIT: What to do if you've upgraded from a previous release:
If you've upgraded Ubuntu from one release to the next, you will probably need to adjust this process. In that case, I would check the manifest file of the newer release (see above) in addition to the initial-status.gz file from the current release. You can easily do that by just adding another comparison. Using just the manifest file will not work, as the manifest file unfortunately does not contain everything that the initial_status.gz file does (I checked).
First of all, let me say that removing python
can lead to many fundamental commands not work anymore. So I don't known if what follow will work.
Secondly, I assume that the package names couldn't be found
error you have, derives from a mispelled name on the command line, or from a package installed locally and not available in repositories.
Then, to obtain a log of removed packages, relatively to the last dpkg
log available (I don't think you need to take into account older logs):
awk '$3 == "remove" { print $1, $2, $4 }' /var/log/dpkg.log | tee list
Then edit the list
file created in the current directory, and only leave lines relative to packages you want to reinstall, based on timestamp of the line. Say you save the modified file to list-mod
.
To reinstall that packages, use the following command:
sudo apt-get --simulate install $(awk '{ print $3 }' list-mod)
I inserted the --simulate
option to see what the command would do. If it is all ok, do the command again with that option removed.
If the command say some packages cannot be found, simply remove them from list-mod
and try again.
Best Answer
Unfortunately, dpkg (the package handler aptitude works on top of) does not specifically save the install date of packages, although there's thoughts of adding it. However, the install date can be found by looking at the date stamp of files written to the directory
/var/lib/dpkg/info
.