Skip to content

Instantly share code, notes, and snippets.

@tsuchm
Last active July 8, 2022 02:08
Show Gist options
  • Save tsuchm/8cf7dfeefbf236b484e97d2ab1ebb4ee to your computer and use it in GitHub Desktop.
Save tsuchm/8cf7dfeefbf236b484e97d2ab1ebb4ee to your computer and use it in GitHub Desktop.
List installed packages which are not depended by other installed packages. In other words, list all required packages.
#!/usr/bin/perl
use strict;
&main();
sub main {
open( my $ph, 'dpkg --status |' ) or die;
my %package;
my %depended;
my $p;
while( <$ph> ){
s/\s+\Z//;
if( s/\APackage:\s+// ){
$p = $_;
}
elsif( m/\AStatus: install/ ){
$package{$p}++;
}
elsif( s/\ADepends:\s+// ){
for my $x ( split( /,\s+/, $_ ) ){
$x =~ s/\s+\(.*?\)\Z//;
$x =~ s/:.*?\Z//;
$depended{$x}++;
}
}
}
for my $p ( sort keys %package ){
next if $depended{$p};
print $p, "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment