history-stats 685 B

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