IT, Linux @ 14 April 2008, “4 Comments”

一宁的 blog 上看到这么好玩的命令:

$history | awk '{a[$2]++} END{for(i in a){printf %5d\t%s\n,a[i],i}}'|sort -rn|head

82 ls
64 cd
44 sudo
42 vim
37 svn
25 lftp
22 ./test.sh
17 memcached-tool.pl
11 ping
11 gvim

下面是改进版,可以加入百分比统计:

$history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a]   CMD[a]/count*100 %  a;}' | grep -v ./ | column -c3 -s   -t | sort -nr | nl | head -n10

1 82 16.4% ls
2 64 12.8% cd
3 44 8.8% sudo
4 42 8.4% vim
5 37 7.4% svn
6 25 5% lftp
7 17 3.4% memcached-tool.pl
8 11 2.2% ping
9 11 2.2% gvim
10 10 2% exit

是不是很有意思,快点回复让我看看你的吧。:)