If I had a running debian system, the following command could be issued to get list of installed packages:

dpkg --get-selections > packages.lst

But now I have only a full backup of root partition (complete system backup) of the working system and nothing more. How can I generate list of installed packages from these files?

  • Only the root partition - not the complete system? Which directories are on this partition?
    – user90883
    Commented Sep 19, 2015 at 17:22
  • I meant "complete system backup", edited question accordingly.
    – ceremcem
    Commented Sep 19, 2015 at 17:57
  • Also take light of this as a way to diff out just the ones you've installed. It will take a little tweeking, but you'll get the idea: quora.com/How-do-I-see-installed-programs-in-ubuntu# Commented Jul 26, 2016 at 23:40

3 Answers 3


chroot into it, and run dpkg would be the easiest thing. See https://superuser.com/a/417004/20798 for how to get a working /proc, /sys, and /dev inside the chroot.

Since you have a working debian system outside the backup, you could probably just use

dpkg --admindir=dir --get-selections

The dir defaults to /var/lib/dpkg, so put the path to your backup's /var/lib/dpkg.

Don't forget that dpkg --get-selections doesn't show which packages were manually installed, and which were only installed to satisfy dependencies (and thus should be auto-removed when no longer needed because newer versions of the packages you actually want have different deps, or because you purge a manually installed package.)

I use aptitude, which makes it easy to mark everything as auto-installed, then go through and mark some packages as manually installed until nothing you want to keep is getting auto-removed. Start with big meta-packages, like build-essential, the Debian equivalents of ubuntu-standard and ubuntu-desktop, and stuff like that. In aptitude, hit r to see the reverse-depends of a package (pkgs that depend on it).

  • 1
    You can use apt-mark or (far more convenient but not installed by default) apt-clone to clone a set of installed packages including the automatic/manual flag. Commented Sep 19, 2015 at 20:50
  • 1
    dpkg --admindir=dir --get-selections also lists deinstalled packages and other non-installed ones. You need to parse it to get only installed packages.
    – terdon
    Commented Sep 20, 2015 at 13:22
  • @terdon: I assume the intended usage was to feed the list to dpkg --set-selections. In which case, run aptitude before letting dpkg actually act on those selections, and mark all the to-be-uninstalled packages as don't-change. Or go through the list and see which cruft you actually want to purge (and change it from deinstall to purge). Commented Sep 20, 2015 at 15:10

Peter's approach is better but you could also just parse /var/lib/dpkg/status which doesn't require a chroot:

 $ perl -00ne 'if(/: install/){/Package:\s*(\S+)/ && print "$1\n"}' /var/lib/dpkg/status

On my machine, that returned the same list of packages as dpkg --get-selections | awk '$NF=="install"{print $1}' (the awk parsing is needed because otherwise it also shows deinstalled packages).

  • downvote, because it gives different set of packages on my running system. I have 4113 packages according to dpkg --get-selections, 3925 packages according to your one-liner and 1473 packages missing in your one-liner.
    – ceremcem
    Commented Sep 20, 2015 at 12:36
  • @ceremcem yes, as I said in my answer, that's because dpkg --get-selections doesn't list only installed packages. It will also show uninstalled ones. Compare the output of my one-liner to that of dpkg --get-selections | awk '$NF=="install"{print $1}' instead. Alternatively, just run dpkg --get-selections | grep deinstall to see the various packages you don't want listed.
    – terdon
    Commented Sep 20, 2015 at 12:39
  • The dpkg_installed command returns 193 less packages than dpkg --get-selections commad. your one-liner has 1204 additional, 1473 missing packages when compared to dpkg --get-selections command and 1204 additional, 1280 missing packages when compared to dpkg_installed command.
    – ceremcem
    Commented Sep 20, 2015 at 12:48
  • @ceremcem what's dpkg_installed? Where can I get it, it sounds useful and I'd like to check this on my machine. I can tell you that here, dpkg --get-selections | awk '$NF=="install"{print $1}' and the perl one-liner return the same list. In any case, there's no point in comparing it to dpkg --get-selections since that prints various things you don't want.
    – terdon
    Commented Sep 20, 2015 at 13:23
  • Pardon me for fabricating something like a non-understandable joke, I used dpkg_installed in place of dpkg --get-selections | awk '$NF=="install"{print $1}'. By the way, I run couple of tests and it seems that there something wrong with my current installation, since I can not find some of my installed applications in dpkg --get-selections list. I'm toggling my downvote till I run these commands on some other installations.
    – ceremcem
    Commented Sep 20, 2015 at 18:27

You can have a listing using of you packages using :

awk '/Package:/ {print $2}' /var/lib/dpkg/status

  • That will not only show installed packages.
    – terdon
    Commented Sep 19, 2015 at 18:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .