In this post I go through how I optimise my bash history. I hope this helps!
Bash history is invaluable. It helps you check that command you ran and now can’t remember, or lookup a command that you ran for a specific task. With this in mind optimising the way your bash history works makes sense. Here is what I have found to work really well:
- Infinite history.
- Infinite history file size.
- Time and date stamp the command (useful although does clutter the output)
- Forcing every command to write immediately to the history file. (a must, as commands won’t get written to the history if bash doesn’t have a clean exit)
- Change location of history file.
Open up your .bashrc file in your favourite text editor, nano for me. Comment out the current bash history settings for file and size and add the following to the bottom of the file.
export HISTFILESIZE= export HISTSIZE= export HISTTIMEFORMAT="[%F %T] " export HISTFILE=~/.bash_supersize_history PROMPT_COMMAND="history -a; $PROMPT_COMMAND"