123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #!/usr/bin/env perl
- use strict;
- our %commands;
- open(HISTORY, "$ENV{HOME}/.histfile") || die "Cannot open history file: $!\n";
- sub hashValueDescendingNum {
- $commands{$b} <=> $commands{$a};
- }
- while (<HISTORY>) {
- my $command = $_;
- if ($command =~ m/^$/) {
- next;
- }
- my @comm = split(' ', $command);
- if ($comm[0] eq "sudo") {
- shift @comm;
- }
- if ($comm[0] eq "..") {
- next;
- }
- $comm[0] =~ s/\.\///;
-
- if (not exists($commands{$comm[0]})) {
- $commands{$comm[0]} = 0;
- }
- $commands{$comm[0]}++;
- }
- foreach my $key (sort hashValueDescendingNum (keys(%commands))) {
- my $value = sprintf "%8s", $commands{$key};
- print "$value\t$key\n";
- }
|