Wednesday, February 17, 2010

How to get the percentage of Command executed?

Get percentage of Command executed

Do you want to know which command on you Linux box has executed the most and also would you like to get the Percentage. This is very Simple and can be achieved useing awk, grep. It can be acheived in many other possible ways too.


root# 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

OutPut:

1 133 13.3% ls
2 127 12.7% cd
3 78 7.8% vi
4 35 3.5% netstat
5 32 3.2% postfix
6 31 3.1% tail
7 30 3% mv
8 29 2.9% telnet
9 29 2.9% ll
10 23 2.3% postqueue

In the above example ls was the most executed command with share of 13.3% following with cd with 12.7 and then rest.

No comments:

Post a Comment