Delete Saved Shell Cmd History in Erlang / Elixir

Jul 30, 2018

To Enable erlang / elixir shell history across sessions:

There are lot of tutorials out there illustrating how to enable persistent shell history in erlang / elixir, one such example is found here , so I am not going to elaborate it here.

What if you wanted to delete your shell history:

There are not many examples as to how to delete them, once they saved. People have even suggested to disable the shell history and re-enable them, which do not help. The saved history is persisted even then. Let’s check the history, how shell history is collected.

Prior to OTP 20:

There was this little erlang package erlang-history written by a brilliant mind known as Fred Hebert, which helped people save their erlang shell history, but later that package was integrated into main erlang OTP package and it is being used by everyone using erlang / elixir.

Later one day, I had this annoying error commands showing up in history:

I searched for hours trying to find a solution to erase the previously saved history, but they were invasive. So I decided to go in deep and explore where it is saved by default, it is done using the group_history module in kernel. Lucky, are those, who had enabled the history with a file name, for them they can just delete or clean the file. But for those, who stick to the defaults, just delete the $HOME/.cache/erlang-history/* or if you are looking for non-invasive solution, you got it…

The group_history module exported just two functions, namely: add/1, load/0

# I am using elixir to illustrate the examples. The same commands can be done via erlang too...
iex(1)> :group_history.load()
[':group_history.load()\n', 'group_history:load().\n']

The above command gives out all the history that it had saved from beginning of time. Ooooo, even your practice commands too...

After a huge exploration, Fred was saving the history using disk_log module, that is when I found a way to clean the saved history. If you type the below command:

iex(2)> :disk_log.accessible_logs()
{[:"$#group_history"], []}

That’s our guy who is saving all of our history, now to clean up the history use the below command:

iex(3)> :disk_log.truncate(:"$#group_history")
:ok

That’s all Folks! We are free from our erlang / elixir shell history.


   erlang (8) , elixir (5) , functional-programming (3)