Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

Append

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 (<= 0.8.0.999-1), network-manager-pptp (<= 0.8.0.999-1), 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?

share|improve this question
1  
Parsing apt-get --dry-run remove looks basically right. It might miss some automatically installed packages that are only needed for automatically installed packages that are only needed by the package you remove. Is that why you don't consider it a suitable answer? –  Gilles Jan 22 '12 at 23:45

2 Answers 2

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
share|improve this answer
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.

share|improve this answer
    
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 '12 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. –  Faheem Mitha Apr 17 '12 at 19:29
    
@FaheemMitha: old post, but still great tip on apt-get remove -s packagename! –  twan163 Aug 10 at 9:31
    
@twan163 Happy it was useful for you. –  Faheem Mitha Aug 10 at 14:54

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.