Parece que dpkg
não mostra explicitamente nenhuma informação sobre as datas de instalação dos pacotes.
Então, para uma única execução, eu usaria algo como o seguinte one-liner:
cat /var/log/apt/history.log |perl -lne 'next unless /^Start-Date: ([^ ]+)/ && $1 ge "2015-04-26" .. 1; next unless /^(Install|Purge|Remove): (.*)$/; $c = $1; $s = $2; $s =~ s/\([^\)]*\)//g; @packages = map { /^(.*?):/ ? $1 : $_} split /\s*,\s*/, $s; if ($c=~/^Install$/){ $h{$_} = 1 for @packages;} if ($c=~/^(Purge|Remove)$/) {delete $h{$_} for @packages;} END{print for sort keys %h;}'
A data de início (x_0) foi codificada no comando ( "2015-04-26"
).
Por vezes, a utilização mais adequada seria um script autónomo, como este installed_packages.pl
:
#!/usr/bin/perl
# use as follows:
# ./installed_packages.pl '2015-04-26' /var/log/apt/history.log
# or
# ./installed_packages.pl '2015-04-26 16:08:36' /var/log/apt/history.log
use strict;
use warnings;
# the script expects start date as first argument
my $START_DATE = shift @ARGV;
# hash (dict) to accumulate installed & not removed packages
my %installed;
# flag to mark the beginning of "interesting" period of time
my $start = 0;
# loop over lines from the input file
while (my $line = <>){
# remove end-of-line character
chomp $line;
# skip everything until date becomes greater (or equal) than our x_0
$start ||= $line =~ /^Start-Date: ([^ ]+)/ && $1 ge $START_DATE;
next unless $start;
# we're only interested in lines like
# Install: tupi-data:amd64 (0.2+git02-3build1, automatic), tupi:amd64 (0.2+git02-3build1), libquazip0:amd64 (0.6.2-0ubuntu1, automatic)
# or
# Remove: aptitude-common:amd64 (0.6.8.2-1ubuntu4)
# + separate action (install/remove/purge) from package list
next unless $line =~ /^(Install|Purge|Remove): (.*)$/;
my ($action, $packages_str) = ($1, $2);
# remove versions from the list (they're in parentheses)
$packages_str =~ s/\(.*?\)//g;
# split single line into array of package names
my @packages = split /\s*,\s*/, $packages_str;
# remove architecture name (comes after ':')
s/:.*// for @packages;
# if packages have been installed, add them all to the hash (dict) of installed packages
if ($action =~ /^Install$/ ){
$installed{$_} = 1 for @packages;
}
# if packages have been removed, remove them all from the hash (dict) of installed packages
if ($action =~ /^(Purge|Remove)$/) {
delete $installed{$_} for @packages;
}
}
# print all installed and not removed packages, in alphabetical order
for my $p ( sort keys %installed ){
print "$p\n";
}
Uso:
./installed_packages.pl '2015-04-26' /var/log/apt/history.log
ou
perl ./installed_packages.pl '2015-04-26' /var/log/apt/history.log
Para uso interativo frequente eu adicionaria a validação de argumentos de script (formato de data de início), implemente a opção -h
para exibir ajuda curta e possivelmente converta a data de início para a opção nomeada ( --start
).
Boa sorte!