Idle Curiosity and Bash

Idle curiosity prompted me to wonder which bash commands I most commonly use. A tweak of configuration, two minutes on the command line and one web service later and I had my answers in graphical form.

  1. First I wanted to ensure that I had a sufficiently large sample of shell commands to get meaningful results. By default the shell I use (bash) only records the previous 500 commands – this is plenty for regular use, but I wanted more, so I modified my .bashrc file and added the following two lines:

    export HISTSIZE=5000
    export HISTFILESIZE=5000

    Impatience prevented me from reporting on a full 5000 shell commands.

  2. The next day I composed the following command line combination. It's too obvious to be worth explaining to those who can use bash and too complicated to be worth explaining for those who can't.

    cat .bash_history | tr '|' '\n' | awk '{print $1}' | \
     egrep -o '([^/]+)$' | sort | uniq -c | sort -nr | awk '{print $2 "," $1}'

    The output is a list of the commands I have previously used in my bash terminals, paired with the number of times I've used them. I acknowledge that this approach will fail to deal with escaped pipes correctly, but my idle curiosity doesn't extend that far.

  3. Finally, I decided to convert the list into a graph for inclusion in this webpage. To do this I used the Jacuba Charts Google gadget by copying & pasting the output into the gadget to generate the chart below.

    Click on the images for larger versions.
    Commands in descending frequency
    Commands in alpabetical order

I've wasted half an hour to discover that the command line program I most frequently use is ls. I think that the high frequency of the exit command might be an anomally caused by using lots of shells simultaneously via Konsole.

The charts were generated from the following files: command-history.txt and command-history-alpha.txt