July 06, 2008

See What Are Your Most Used Shell Commands

This script looks into history and prints up the 10 most used commands issued in the shell:

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

Example output on my system, freshly installed for about a week:

55 ls
37 cd
27 apt-cache
14 su
10 j=1;
10 file
9 ps
8 killall
8 dcop
8 clear
The script itself was taken from here. UbuntuForums is a great resource for these kinds of scripts, and there are several threads there about it too.

Updated: Jul 06, 2008 (Created: Jul 06, 2008)

5 comments:

Anonymous said...

In case anybody wonders, you can modify the number of lines shown by adding an option to tail. Like this: tail -20.

I think 20 lines gives a better idea. And it would also be interesting to differentiate between commands run as regular user and root, but on systems that use sudo it's not so straightforward.

Anyway, I don't use sudo. So here are my top 20 commands as a regular user:


128 mp
82 ls
70 mcdf
66 php
52 echo
49 crypt
48 sh
48 joe
48 df
47 egrep
43 startx
42 cd
41 cat
32 ssh
29 killall
29 du
28 wmctrl
23 xmlrpc
21 xprop
21 apt-file


mp and mcdf are aliases for mplayer, while the rest are regular commands. My system has been installed for a while, but as you can see the numbers are not very high. Most likely due to the fact I use Midnight Commander a lot, hence no need to run many commands "by hand". BTW, I launch mc through a shortcut, directly in a terminal, that's why the "mc" command doesn't appear in the top.

It's a different story for the root user:


888 apt-get
652 joe
516 ls
364 cd
292 rrdstorm
234 cat
193 df
184 mc
181 dpkg
163 rmmod
155 make
142 lsmod
130 /etc/init.d/x-lirc
124 modprobe
114 umount
109 netstat
108 setserial
97 ps
96 man
88 tail


There are more exotic commands here, and you can see the numbers are quite big as well, since a lot of the maintenance work done as root is best done in the console (at least for me).

Craciun Dan said...

Nice list you've got there. Here's mine for GUI (fresh install so there aren't many to list):


98 apt-get
44 apt-cache
13 exit
8 ls
7 ln
6 nano
5 cd
3 rm
3 clear
2 make
2 ./install.sh
2 bash
1 whereis
1 wget
1 ./UT2004-LNX-Demo3334.run
1 uname
1 umount
1 sudo
1 pppoeconf
1 ./kits/css.apps/NVIDIA-Linux-x86-100.14.19-pkg1.run

Anonymous said...

I see you all are debian loosers... STFU with all this rubbish.

bahathir said...

You can simplify the script as bellow.

history | awk '{print $2}' | sort | uniq -c | sort -nr | head -10

Here is my result.
85 cd
70 make
36 ls
24 sudo
19 rm
18 grep
15 less
14 ssh
14 fg
12 rdesktop

Anonymous said...

As always, there is more than one way to do things in *nix. This is an alternative, geekier method:
history | awk '{a[$2]++} END{for(i in a){print a[i], i}}' | sort -rn | head