Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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 '10 at 8:17

4 Answers 4

up vote 3 down vote accepted

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?

share|improve this answer

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
1831
dpkg --get-selections |grep -v ^lib | wc -l
1060
share|improve this answer
    
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 '10 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)
do
    test -e $LOG && gunzip -c  $LOG>> /tmp/dpkg.full
done
for LOG in $(ls -rt /var/log/dpkg.log /var/log/dpkg.log.[0-9]  /var/log/dpkg.log.1[0-9]) 
do
    test -e $LOG && cat $LOG >>/tmp/dpkg.full
done
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
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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