I want to backup my list of manually selected packages in Ubuntu, without listing packages installed as dependencies. For example,

dpkg --get-selections

returns a complete list of all installed packages, manually selected as well as dependencies. How can I filter dependencies?

  • My goal is to install a new Ubuntu system with the same setup as my current, and I do not want to install my old dependencies as manually selected. The current system is actually Ubuntu 9.10 and the new system is 10.04 beta2, so the dependencies are not necessarily equal. Any suggestion that can lead to my goal would be appreciated.
    – Johan
    Apr 19, 2010 at 8:17

4 Answers 4


I hacked myself a solution :)

dpkg --get-selections | cut -f 1 > /tmp/all
apt-mark showauto > /tmp/auto
diff /tmp/all /tmp/auto | grep '<' | sed 's/.* //'

That will first generate a complete list "all" of installed packages, then a list "auto" of automatically installed ones, and finally create a list of differences from all and auto, which is the list I need.

Any better suggestions?


You could filter out the lib packages and manually filter the remaining ones. I don't think that there's a standard way to do this.

dpkg --get-selections |wc -l
dpkg --get-selections |grep -v ^lib | wc -l
  • Not good enough. Dependencies can be others than libs and libs are not always dependencies. I have installed my system manually now, but I still find the question interesting.
    – Johan
    Apr 19, 2010 at 14:18

# ASSUMING your dpkg Logs go back to the initial machine install

###(May/Probablly NOT work across dist-upgrades)

apt-mark showauto >/tmp/auto.pkgs

Create a full dpkg timeline log
cp /dev/null /tmp/dpkg.full
for LOG in $(ls -rt /var/log/dpkg.log.[0-9].gz  /var/log/dpkg.log.1[0-9].gz)
    test -e $LOG && gunzip -c  $LOG>> /tmp/dpkg.full
for LOG in $(ls -rt /var/log/dpkg.log /var/log/dpkg.log.[0-9]  /var/log/dpkg.log.1[0-9]) 
    test -e $LOG && cat $LOG >>/tmp/dpkg.full
Now Filer out the packages initially installed by the OS
awk -v initialinstall=1 '
   / install grub-pc / {initialinstall = 0; next;}                     
   / install / {if ( initialinstall == 0) print $4;}
' /tmp/dpkg.full | grep -vf /tmp/auto.pkgs >~/iInstalled.pkgs

If you want a list of packages that are not marked as automatically installed (which is not always the same as not being a dependency), you can do this in a simpler way using aptitude like so:

aptitude search ~i | grep "^i   " | awk '{ print $2 }'

If you are really concerned with weeding out all dependencies, you can look into the ~R and ~D search patterns. I think aptitude is the currently recommended front-end to dpkg and apt. You will find that it has a number of really useful command-line options, in addition to the ncurses interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.