This lists packages added after Ubuntu was installed.
When I upgrade from one version of Ubuntu to another, I do a fresh install. I have a procedure on my personal wiki with all of the steps to move in. Part of that is restoring data from backup, Part is restoring or recreating configuration files.
But what about software packages? There is a baseline of packages that I use all the time, but I also add packages ad hoc as required. It is convenient to get a list of what is installed.
Here’s a one-liner to list installed packages on Ubuntu:
cat /var/log/installer/initial-status.gz | gzip -d | grep '^Package:' | awk '{ print $2}' > tmp.txt && aptitude search -F %p '~i!~M' | awk '{ print $1}' | grep -v -F -f tmp.txt && rm tmp.txt
The list that is returned is pretty good. You can save the output to a text file and edit that file to get the list of packages you want to install on the new system.
Here’s how to output to packages.txt:
cat /var/log/installer/initial-status.gz | gzip -d | grep '^Package:' | awk '{ print $2}' > tmp.txt && aptitude search -F %p '~i!~M' | awk '{ print $1}' | grep -v -F -f tmp.txt > packages.txt && rm tmp.txt
As you can see, it greps out a list of packages included in the original install, grabs the second field with awk and stuffs the result in a temporary file. Then a list of installed packages is generated, again using awk to parse out the package name field. Then grep is used to compare thee two lists and output just the packages installed after initial installation.
Here is what I have installed:
apache2 apache2-utils apache2.2-common audacity bluefish build-essential figlet flashplugin-installer gimp gnome-do google-chrome-beta inkscape keepassx libapache2-mod-php5 mailutils mysql-server ninvaders nvidia-current padre php5 php5-cli php5-common php5-curl php5-dev php5-gd php5-imagick php5-mcrypt php5-memcache php5-mysql php5-pspell php5-snmp php5-sqlite php5-xmlrpc php5-xsl phpmyadmin skype vim vlc winff xtightvncviewer
So, this is a list of 40 packages installed on my machine, out of a total of 1560 packages returned by “dpkg –list” (thanks, Mark!). Just those I installed, not everything including all of baseline Ubuntu.
Or, you can use this:
dpkg –list
or export to a .txt with:
dpkg –list > /home/username/Desktop/programs.txt
@Mark: That returns all of the packages installed, both Ubuntu’s standard packages as well as those installed by me (1560 packages in my case, instead of 40). The one-liner returns the packages installed AFTER Ubuntu was installed, which is useful when moving to a fresh install.
Hey, I know this is a fairly old post but, this is (almost) exactly what I was looking for. I was (am) deploying new Ubuntu servers and wanted to mirror the installed programs on the new servers from an old server. When I ran the script, it appeared to have only pulled out the stuff I installed, but I later noticed it did miss at least one program (rsh-redone-server). Why would this be? Unfortunately, I can’t use this command because I need the servers to be identical. Is there maybe a better way to do this? (eg, compare server1’s installed programs vs server2’s and show only the differences?). Regardless, I appreciate your attempt at providing an easy way to upgrade.
Interesting approach!
However, I have three questions:
1. Which version of Ubuntu are you writing about?
2. I do not have /var/log/installer/initial-status.gz – this file does not exist. How can I
(re-)generate it?
3. What exactly does aptitude search -F %p ‘~i!~M’ ?
Thanks!