Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
add comment

migrated from stackoverflow.com May 4 '10 at 12:06

This question came from our site for professional and enthusiast programmers.

3 Answers

up vote 25 down vote accepted

put that into .bashrc:

export HISTSIZE=

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

From "man bash":

 If HIST‐FILESIZE is not set, no truncation is performed.

That means .bash_history is never truncated

Also the same seems to apply to HISTSIZE, although I couldnt 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.

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

share|improve this answer
I had not seen the HISTTIMEFORMAT before - I can confirm that it works as expected. You can easily see it working by adding it to /etc/profile (if you want all users to have this), log out and log in again, do something like ls, then history. –  Snap Shot Sep 19 '13 at 20:38
add comment

After many large, ugly iterations and weird edge cases over the years, I now have a concise section of my .bashrc dedicated to this.

# Eternal bash history.
# ---------------------
# Undocumented feature which sets the size to "unlimited".
# http://stackoverflow.com/questions/9457233/unlimited-bash-history
export HISTSIZE=
export HISTTIMEFORMAT="[%F %T] "
# Change the file location because certain bash sessions truncate .bash_history file upon close.
# http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login
export HISTFILE=~/.bash_eternal_history
# Force prompt to write history after every command.
# http://superuser.com/questions/20900/bash-history-loss

Note: every command is written immediately after it's run, so if you accidentally paste a password you cannot just "kill -9 %%" to avoid the history write, you'll need to remove it manually.

Also note that each bash session will load the full history file in memory, but even if your history file grows to 10MB (which will take a long, long time) you won't notice much of an effect on your bash startup time.

share|improve this answer
Could I put this setting globally in global bashrc so that it overrides settings for all users ? –  user01 Mar 14 at 22:06
add comment

A different concept (may not be applicable) but you can have unlimited history when using shell-sink.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.