one liner history command counter
Wondering what commands you use the most, try this one liner:
$ history | perl -ne 'END { map {print ++$i.": $_\n";} splice(@{[sort {$h{$b}<=>$h{$a}} (keys %h)]},0,5); } m/\s+\d+\s+(.*)/; $h{$1}++;'
In one of the servers I use I got:
1: ls 2: fg 3: cd .. 4: sudo tail -f /var/log/httpd/error_log 5: cd
Well, I actually added:
alias j=jobs alias vl='sudo tail -f /var/log/httpd/error_log'
To my .bashrc after this.
Take a look at the -a option for Perl in the perlrun page. It takes care of the splitting for you. You'll get your args in @F, so you don't have to do that regex to get your fields split apart.
For giggles, I've golfed it a wee bit:
Ooops... Margins are cutting part of the code.
If you want to golf this, Unix > Perl: