<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>The BFC Computing Weblog: Tag sysadmin</title>
    <link>http://blog.bfccomputing.com/articles/tag/sysadmin</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>My God, It's Full of Source!</description>
    <item>
      <title>Package Cleanup - Leaves and Orphans</title>
      <description>&lt;p&gt;On an RPM-based system, yum-utils provides a utility called &amp;#8216;package-cleanup&amp;#8217;.  It has two useful options:&lt;/p&gt;

&lt;p&gt;&amp;#8211;orphans shows RPM packages that do not belong to any currently-configured repositories, and:&lt;/p&gt;

&lt;p&gt;&amp;#8211;leaves shows RPM packages for which there are no dependencies; that is removing them won&amp;#8217;t trigger the removal of other packages.  By default it&amp;#8217;s concerned with libraries, but &amp;#8211;all removes that restriction.&lt;/p&gt;

&lt;p&gt;So, ideally you&amp;#8217;d like to run:&lt;/p&gt;

&lt;p&gt;package-cleanup &amp;#8211;orphans &amp;#8211;leaves &amp;#8211;all&lt;/p&gt;

&lt;p&gt;to get a list of all the packages you might want to consider for cleanup, say before or after an upgrade.  But package-cleanup doesn&amp;#8217;t support that.&lt;/p&gt;

&lt;p&gt;So, here&amp;#8217;s a little perl script, called &lt;code&gt;leavesorphans.pl&lt;/code&gt; on my system that will run package-cleanup twice and print for you the intersection of the two sets:&lt;/p&gt;

&lt;blockquote&gt;&lt;pre&gt;#!/usr/bin/perl -w
use strict;
use warnings FATAL=&gt;'all';

use Data::Dumper;

my @orphans = `package-cleanup --orphans`;
my @leaves = `package-cleanup --leaves --all`;

my (%orphans,%leaves);
foreach my $orphan (@orphans) {
    $orphans{$orphan} = 1;
}
foreach my $leaf (@leaves) {
    $leaves{$leaf} = 1;
}

my (@matches);
foreach my $orphan (keys %orphans) {
    foreach my $leaf (keys %leaves) {
        if ($orphan eq $leaf) {
            push (@matches,$orphan);
            delete $leaves{$leaf};
        }
    }
}


foreach my $match (@matches) {
    if ($match !~  m/Setting up yum/) {
        print $match;
    }
}

&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;I recently ran it and found a few packages that were lingering on my system since Fedora Core 4, just wasting system resources.   If all of your proper packages belong to a repository you can simply pipe the output of the command to &lt;code&gt;xargs rpm -e&lt;/code&gt;.  I&amp;#8217;m not quite that slick, so I manually reviewed the list and kept the packages I had installed by hand.&lt;/p&gt;</description>
      <pubDate>Tue, 30 Sep 2008 14:12:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:9e11f420-0fbd-420a-8354-da0056daaa02</guid>
      <author>Bill McGonigle</author>
      <link>http://blog.bfccomputing.com/articles/2008/09/30/package-cleanup-leaves-and-orphans</link>
      <category>BFC Computing</category>
      <category>Development</category>
      <category>Open Source</category>
      <category>Linux</category>
      <category>sysadmin</category>
      <trackback:ping>http://blog.bfccomputing.com/articles/trackback/4785</trackback:ping>
    </item>
  </channel>
</rss>
