For each package I have installed I would like to know which packages would be installed if I uninstall it. An example of the output I need is (package: list of deps):

abc: foo bar
bcd: baz abc
bdd: baz fuubar


If I check what really would be removed if I remove the package ppp using apt-get:

$ echo $(apt-get --dry-run remove ppp | grep '^Remv ' | cut -d' ' -f2)
gnome-ppp mint-meta-xfce network-manager-pptp-gnome network-manager-pptp wvdial pppoeconf pppoe pptp-linux pppconfig ppp

I see that it is different from what apt-cache show gives me (which I do not think include recursive dependencies):

$ apt-cache show ppp | grep '^Breaks: '
Breaks: network-manager (<=, network-manager-pptp (<=, pppdcapiplugin (<= 1:3.9.20060704+dfsg.1-1)

Append 2

Is dpkg --get-selections | cut -f1 a reliable way to get a list of installed packages to iterate over?


3 Answers 3


You asked a few different question here, I hope I can at least help on one or two.

To list all installed packages, use dpkg to output in a field separated list

dpkg -l 

To just get the package list, without extra fields, so you can pipe it elsewhere.

dpkg -l | awk '{print $2 }' # Pipe to grep after the awk, or glob from dpkg

For example, if I want to remove an old kernel,

apt-get purge `dpkg -l linux* | awk '{print $2}' | grep 3.0.0-12`

The easiest way to go through all unneeded dependencies, is with debfoster. It runs interactively and goes through what you want, their dependencies and can remove or list what is not a recursive dependency.

To list all recursive dependencies of a specific package,

debfoster -d $PACKAGE ## PACKAGE is the specific package.

After you have executed debfoster you can check any dependents a package has also,

debfoster -e $PACKAGE ## PACKAGE is the specific package.

A really great way to list 'orphaned' packages, is with deborphan. Run deborphan without options, and it will list all 'orphaned' packages. An 'orphan' is a package that nothing depends on, and you have not explicitly installed.

I also like to clean any 'orphaned' packages, after a fresh install. After I have removed specific packages, you can get anything missed by apt-get autoremove --purge with,

apt-get purge `deborphan`

Finally sometimes you don't --purge and end up with package 'leftovers', the newer versions of apt-get can automatically remove them. To remove all 'leftovers' from uninstalled packages run,

apt-get autoclean

If you don't have the new version of apt-get, you can always remove them with these commands. They error if no 'leftover' files exist, it seems like autoclean can miss some occasionally regardless.

dpkg --list |grep "^rc" | cut -d " " -f 3 | xargs dpkg --purge
  • debfoster still exists, but is considered superseded by features in aptitude Apr 4, 2018 at 21:23
apt-cache show pkgname1 pkgname2...

will (among other things) list these (runtime) dependencies. This is usually adequate, unless you are feeding it to a machine for further processing. If you want it in exactly the format you stated, you will probably have to write a script.

  • Sorry, I formulated my question incorrectly. I am interested in knowing which packages would be uninstalled for each package I have installed. And I also need to list all packages I have installed.
    – Deleted
    Jan 21, 2012 at 22:05
  • 2
    @Deleted: Sorry, I didn't see this comment till now. In response to "which packages would be uninstalled for each package I have installed" (I assume you want this question answered on a per-package basis) try apt-get remove -s packagename. Listing all packages you have installed is just dpkg -l. Apr 17, 2012 at 19:29
  • @FaheemMitha: old post, but still great tip on apt-get remove -s packagename!
    – twan163
    Aug 10, 2014 at 9:31
  • @twan163 Happy it was useful for you. Aug 10, 2014 at 14:54

I think yo have to continue and create an loop for same thing:

apt-cache depends libtext-wrapi18n-perl |xargs apt-cache depends

Of course remove headers.

  • 10
    apt-cache depends has a recures option apt-cache depends --recurse libtext Apr 4, 2018 at 21:25

You must log in to answer this question.

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