Visualising how I use the Terminal

Description

After switching full time to using Mac OS for development, I have been using the terminal extensively. I wanted to find out what types of commands I use more often and whether there are any trends, such as using a particular set of commands more frequently over time. To visualise my terminal usage I created a treemap which displays how frequently I used each type of command. All commands are categorised into different types such as “Package managers” and “Git”. For each command type I also included a line chart which shows frequency of execution over time (on a monthly basis). This is visible when hovering over a corresponding treemap cell. Covered time period is from start of November 2017 until end of June 2018.

Data extraction and preparation

I extracted the command data from .bash-history, a file where each executed command is saved. By default only a limited number of commands is stored, however it is possible to increase this by assigning a value to the HISTFILESIZE variable in .bash-profile. I set it to 1000000, which should be enough for a while :)

.bash-history also normally doesn’t save the time and date of an executed command, but I enabled the addition of timestamps for each command by adding HISTTIMEFORMAT='%F %T ' to .bash-profile.

To extract and clean the data from .bash-history I wrote a Node.js script, although moving commands into their categories required a bit of manual work. Categorisation itself was rather subjective and I ended up coming up with categories that simply made sense to me.

Visualisation

To create the visualisation itself I used D3.js.

Looking at the result, what becomes apparent is that I tend to use the terminal mostly for a limited set of purposes such as Git and moving around directories. The “Basic manipulation” category is dominated by cd command and its aliases — this shows that I still rely a lot on Finder to perform file operations. This is definitely something that I would like to change in the future by using commands for a more diverse set of tasks.

Notes

All commands with fewer than 5 entries and misspelled ones were excluded. Commands which were run with sudo were included as normal commands. I aggregated the same commands with different attributes into one, so for example git add and git commit both count towards git. Aliases which I use for certain commands, for example to quickly move to a certain directory, are aggregated under alias in each particular category.