# Find all user-installed packages

Is there any way to get a list of all user-installed packages on an Ubuntu system, i.e. the packages that were installed on top of the default installed packages?

(The idea is to get a comprehensive list that can be used to install the same packages on a clean Ubuntu installation)

-

Look at these files,

1. '/var/log/installer/initial-status.gz' -- your primary installation
• this file date would be your installation date (i think)
2. '/var/log/dpkg.log' update timeline (this is what you want)
3. '/var/log/apt/term.log' -- things apt updated on your system
4. '/var/cache/apt/archives/' will contain the deb packages downloaded for installation

Update: use the following two steps for exact list of new installs,

execute: grep -w install /var/log/dpkg.log > full-list.log
Look at lines beyond the /var/log/installer/initial-status.gz timestamp

Since, you want to get a clean installation on another system with these packages,
you could even copy the 'deb' files from the 'cache/apt/archives' path
to that of the new installation and get them installed in one shot (without downloading them again).

-
Thanks for the tip. It's useful, although I was looking more for a single command to get this list. cat /var/log/dpkg.log | grep 'install ' seems to come close if I ignore the items installed up to the installation date/time –  Rabarberski Sep 29 '09 at 11:49
Adding a reason for the down-vote would help understand a problem in the answer, if there is one. Would also lead to better answers in future. –  nik Oct 4 '09 at 6:25
Oeps, the downvote was accidentally mine. I had already upvoted your answer. When I tried to mark your answer as 'final' I missclicked and hit the down vote arrow. Trying to undo it displayed the message: "Vote too old to be changed, unless this answer is edited." Sorry nik, both for the downvote and the confusion. :-( –  Rabarberski Nov 10 '09 at 13:58
@Rabarberski, well that happens... no harm done. –  nik Nov 10 '09 at 16:31
does not work if /var/log/installer does not exist, like on a server install. Also it would make sense to add VERSION NUMBERS if you are talking about "Ubuntu" - which Ubuntu? –  user99950 Oct 2 '11 at 13:18

Just for grins, I put together a one-liner (here split for clarity) that figures out packages manually installed, excluding those installed initially and any packages automatically installed:

comm -13 \
<(gzip -dc /var/log/installer/initial-status.gz | sed -n 's/^Package: //p' | sort) \
<(comm -23 \
<(dpkg-query -W -f='${Package}\n' | sed 1d | sort) \ <(apt-mark showauto | sort) \ )  This works both in bash and in zsh. - This works almost perfectly, except it seems to print out a bunch of libraries installed during the initial install. There's a bunch of libtiff, libxcb, etc which I didn't install myself. This answer: superuser.com/a/105000/24349 takes care of that by sorting according to install time and removing everything before the system install time. Great (ab)use of shell! – haxney Feb 23 '12 at 20:12 Based on the information above, I wrote a short Python script to list packages that were manually installed. See this link. Feel free to use it although I assume no responsibility for it. However, feedback and suggestions are always welcome. - Brilliant! It takes a while to run, but it's the only solution I've found which does exactly what I need! – haxney Feb 23 '12 at 20:05 Check my answer here to a related question: How can I display the list of all packages installed on my Debian system?. Some of the other answers on the question also contain nice suggestions on getting such a list. This question should be marked a duplicate since the earlier question also covers this question, but it might be useful to have this question stand on its own so it's easier to find. - assuming you have a consistent history and use aptitude: history | grep -e "^..... aptitude install" would list only the packages which you installed with aptitude install ... duh - This is a hack-job, but it completely works. First, go to http://releases.ubuntu.com/maverick/ (or whatever version of Ubuntu you're using) and grab the *.manifest file that is associated with the version of Ubuntu you're using. Then, run the following script (replacing <manifest file>, angle brackets and all, with the path to the file you downloaded. You can always append > output to the end to make a file dump. diff --suppress-common-lines <(sed 's/ .*//' <manifest file>) <(dpkg --get-selections | sed 's/[ \t].*//') | grep '>' | sed 's/[>] //'  - Thanks geekosaur, nice code. I used it but it took a while to figure out how to get it working. Here's how I did it in Ubuntu 11.10—it works in the bash terminal: comm -13 \ <(gzip -dc /var/log/installer/initial-status.gz | sed -n 's/^Package: //p' | sort) \ <(comm -23 \ <(dpkg-query -W -f='${Package}\n' | sed 1d | sort) \
<(apt-mark showauto | sort) \
) > user-installed-packages


Then to add a tab—\t—and install on each line:

sed 's/$/\tinstall/' user-installed-packages >uip  Then on the new machine: sudo dpkg --set-selections < uip  And to install the packages: sudo apt-get dselect-upgrade  - Another way to do this is by determining what has been installed based on your "tasks" which determine the base packages to install according to your initial needs. tasksel --list-tasks  At the very least you'd have server. However, you may choose to have more. For each of those tasks you have installed, you can get a list of packages that are installed the following command does it all in one line (broken down for clarity) for the ones I have chosen in my installation: (tasksel --task-packages server ; \ tasksel --task-packages openssh-server ; \ tasksel --task-packages lamp-server) | sort | uniq  A generic approach to the above would be: (for a in$( tasksel --list-tasks | grep "^i" | awk '{ print $2 }' ) ; \ do tasksel --task-packages$a; done) | sort | uniq


Now use apt-cache depends --installed -i --recurse <packagename> | grep -v "^ " to get a list of dependencies used by all the packages defined in the task. This can be done in one line as follows

apt-cache depends --installed -i --recurse \
$(for a in$( tasksel --list-tasks | \
grep "^i" | \
awk '{ print $2 }' ) ; \ do tasksel --task-packages$a; done) | grep -v "^ " | sort | uniq


The following lists all the packages that are installed in your system (not including dependencies).

dpkg --get-selections | grep "[[:space:]]install" | awk '{print $1}'  Now use the comm command to find the ones that are in the second list only (i.e. ignore those that are in both files and just the first file) comm -13 <(apt-cache depends --installed -i --recurse \$(for a in $( tasksel --list-tasks | \ grep "^i" | \ awk '{ print$2 }' ) ; \
do tasksel --task-packages $a; done) | grep -v "^ " | sort ) \ <( dpkg --get-selections | grep "[[:space:]]install" | \ awk '{print$1}' | sort)

-