Monday, November 12, 2007

My favorite shell commands

The below one line shell script calculates the number of executions of commands and sorts the result.

history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort -rg

Here is the result of this script on my Ubuntu.

66 ls
40 cd
32 sudo
32 mvn
31 ps
29 clear
26 more
22 vi
19 tail
18 kill
16 ssh
13 rm
13 eclipse
11 tomcat_start.sh
10 ll
10 find
9 locate
9 findJar
6 ifconfig
5 ln

Most frequently used command is "ls". I was surprised to see "mvn" in the 4th place. As you can see I am developing (eclipse), testing-packaging (mvn) and deploying (tomcat_start.sh) web applications written in java these days. I have also "kill"ed a serious number of processes :)

Try this script to see what commands you use frequently.

2 comments:

Anonymous said...

That's quite cool but it doesn't work if you've got the following in your ~/.bashrc:

HISTCONTROL=ignoredups

İlkin Ulaş BALKANAY said...

HISTCONTROL was set to "ignoreboth" by default. (Ubuntu 7.10)

HISTCONTROL=ignoreboth

This causes any lines matching the previous history entry (last entered line) not to be saved. Also lines that start with whitespace will not be saved.