Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

migrated from May 4 '10 at 12:06

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

up vote 53 down vote accepted

put that into .bashrc:

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 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
This does not actually work for many cases and bash history still gets truncated. See my answer below for a more complete solution. – fotinakis May 21 '14 at 18:34
Warning: this causes headaches with gdb; if you set an HISTSIZE variable it will take it as a 0, thus disabling history size entirely. – Matteo Italia Dec 5 '14 at 8:37
notes: you don't need export, HISTFILESIZE is in number of lines (not bytes), and history file truncating happens when you set variable HISTFILESIZE (and when shell exits). So don't set it twice in your config file with different values... – vaab Jan 23 '15 at 2:17

(reposting my answer from

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

First, you must comment out or remove this section of your .bashrc (default for Ubuntu). If you don't, then certain environments (like running screen sessions) will still truncate your history:

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)

Second, add this to the bottom of your .bashrc:

# Eternal bash history.
# ---------------------
# Undocumented feature which sets the size to "unlimited".
export HISTSIZE=
export HISTTIMEFORMAT="[%F %T] "
# Change the file location because certain bash sessions truncate .bash_history file upon close.
export HISTFILE=~/.bash_eternal_history
# Force prompt to write history after every command.

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 '14 at 22:06
The history file gets truncated when you set HISTFILESIZE, this is why you should remove any occurence of such event except the one you want. It'll be also truncated on shell exit (but that is expected). And you shouldn't need export. – vaab Jan 23 '15 at 2:22

Include in ~/.bashrc:

# append a session's history on shell exit
shopt -s histappend

This answer satisfies the following criteria:

  1. a separate master history (no session can interrupt your history)

  2. automatic history writing (no hotkeys)

  3. infrequent writes (no appending after each command)


On interactive startup, if $HISTFILESIZE is set to a number, bash truncates $HISTFILE to that number. On interactive close, if the shell option histappend is set, bash appends $HISTSIZE lines to $HISTFILE, otherwise it overwrites $HISTFILE.

tips for OSX (Terminal)

Every time a tab is created in Terminal, ~/.bash_profile is read, which means bash doesn't go on to read your ~/.bashrc. Add the following line to your ~/etc/bash_profile:

# if bashrc has content, source it
[[ -s ~/.bashrc ]] && . ~/.bashrc

tips for screen

If you use screen, your configuration file is ~/.screenrc. If you want screen to record history, you just need to set it to use a login shell which will source your bash startup files (and record your history).

# use bash, make it a login shell
defshell -bash
share|improve this answer

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

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .