How to Enable Unlimited Bash/Shell History

bashlinuxshell

Is there a way to define an unlimited history in Bash ?

Best Answer

Add this to your .bashrc (Linux) or .bash_profile (MacOS):

export HISTFILESIZE=
export HISTSIZE=

There you go, unlimited history. Currently I have 27000 entries :)

From man bash:

If HISTFILESIZE is not set, no truncation is performed.

That means .bash_history is never truncated

Also the same seems to apply to HISTSIZE, although I couldn't find that documented.

Another neat feature I'm going to try is this:

If the HISTTIMEFORMAT variable is set, time stamps are written to the history file, marked with the history comment character, so they may be preserved across shell sessions, like the following:

export HISTTIMEFORMAT="%F %T "

Let me know if you have tried that already...

Related Question