history-stats 725 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env perl
  2. use strict;
  3. our %commands;
  4. open(HISTORY, "$ENV{HOME}/.histfile") || die "Cannot open history file: $!\n";
  5. sub hashValueDescendingNum {
  6. $commands{$b} <=> $commands{$a};
  7. }
  8. while (<HISTORY>) {
  9. my $command = $_;
  10. if ($command =~ m/^$/) {
  11. next;
  12. }
  13. my @comm = split(' ', $command);
  14. if ($comm[0] eq "sudo") {
  15. shift @comm;
  16. }
  17. if ($comm[0] eq "..") {
  18. next;
  19. }
  20. $comm[0] =~ s/\.\///;
  21. if (not exists($commands{$comm[0]})) {
  22. $commands{$comm[0]} = 0;
  23. }
  24. $commands{$comm[0]}++;
  25. }
  26. foreach my $key (sort hashValueDescendingNum (keys(%commands))) {
  27. my $value = sprintf "%8s", $commands{$key};
  28. print "$value\t$key\n";
  29. }