A couple of years ago I wrote about saving all the commands I ever ran in the terminal into a "persistent history" file, for later lookup. Since some people asked me whether this ended up being worthwhile, here's a short redux.

The TL;DR version is - keeping persistent history has been one of the best productivity hacks I ever put to use; I rely on it daily, and would be much less productive without it.

Before doing this, the only way I had to remember which commands/flags are needed to run something was to write it down in all kinds of notes files, personal wikis and so on. It was cumbersome, unorganized and time-consuming to reuse. With the .persistent_history file automatically populated by Bash from any terminal I'm typing into, and being kept in a Git repository for safekeeping, I have quick access to any command I ever ran. It's a life safer for someone who spends as much time in the terminal as me. I warmly recommend it, or some equivalent approach, to anyone who is using Linux daily.

Interestingly, at the time of the original post I was worried that with time this file will grow too long and will have to be trimmed. That turned out to be a completely needless worry. In over two years of using it at work, my .persistent_history is somewhat over 6 MB long, with ~60000 lines [1]. It takes a negligible amount of time to append to it and to search within it (15 milliseconds for a full search is the most I was able to measure). It doesn't even matter if you have a SSD or a hard drive as your main storage device; since the file is continously written to, it's almost certainly paged into memory most of the time anyway.

Also, I posted a histogram of the 10 most commonly used commands on my home machine for hobby hacking, so it's interesting to revisit that. Here's a histogram for the past year:

git          : 1564
ls           : 861
gs           : 669
cd           : 546
vi           : 543
make         : 538
ll           : 388
pssc         : 379
PYTHONPATH=. : 337
python       : 286

As the original post foresaw, the impending switch from Mercurial to Git for my personal projects, along with spending much less time on CPython core development have pushed hg to the fringes, and Git is certainly the most used command now (gs is my alias for git status). Python should be higher than it appears because commands starting with PYTHONPATH=. always precede python. The rest is a fairly expected bunch from a terminal hermit. pssc is one of the aliases I use for pss, which is why you don't see grep or find in the list.

I placed the Bash code enabling persistent history, along with the Python script I used to compute the command usage histogram shown above on Github.


[1]In reality there were likely many more commands, but the script does some amount of de-duplication - it won't write down a command if it's exactly the same as the last one written. For example, if you spend the whole day hacking in an editor and rerunning python foo.py every couple of minutes, the only commands that will be written in the history are opening the editor and then a single instance of python foo.py.

Comments

comments powered by Disqus