12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #!/usr/bin/perl
- use strict;
- use warnings;
- 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";
- }
|