135

The default size of history in Ubuntu is 1000 but it's too small. I want to change it to 10000, So I append

export HISTSIZE=10000
export HISTFILESIZE=10000

to '~/.profile' and 'source' it

source .profile

then I run

echo $HISTSIZE
echo $HISTFILESIZE

1000 was displayed for both but I reboot my computer it went 'default'. Why doesn't it work?

Mitoxys
  • 1,451
  • 2
  • 10
  • 5
  • 5
    You have a typo here in the question: export HISEFILESIZE=10000 (although it seems you didn't in your .profile if the echos worked). Just in case someone looks at it here, it should be HISTFILESIZE – Leo Gallego Aug 07 '18 at 01:15

3 Answers3

129

I tried the same thing, only to discover that sneaky Ubuntu sets these variables in ~/.bashrc by default, which is executed instead of ~/.profile for non login shells such as just opening a terminal window. Changing these lines in ~/.bashrc fixed it for me:

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
Paul
  • 7,007
  • 3
  • 23
  • 30
  • 6
    hisfilesize is in KB? – Patoshi パトシ Jul 31 '14 at 14:21
  • 19
    @duckx No, HISTFILESIZE is in number of line stored in the history file, while HISTSIZE is the number of line stored and available by each shell process (and then saved to HISTFILESIZE). Note that with no value (or non-number, or negative), then no limiting occurs. – vaab Jan 23 '15 at 02:01
  • 3
    This does not work for some reason on XFCE Terminal – Michal Przybylowicz Dec 30 '15 at 11:50
  • 1
    @MichalPrzybylowicz: could be fixed by writing /etc/bash.bashrc if that's acceptble to you. See below. (maybe it was also the missing export) – serv-inc Apr 19 '18 at 08:40
  • Don't forget if you're using ZSH to throw it in your ~/.zshrc If you're on a modern version of Mac OS you may not even have a .bashrc ;) – CTS_AE Oct 14 '20 at 01:23
  • 1
    @vaab: According to man bash, the default value of HISTSIZE is 500 commands: "The shell sets the default value to 500 after reading any startup files." – Matthias Braun May 27 '23 at 08:58
74

From the Bash Reference Manual:

HISTSIZE 
    The maximum number of commands to remember on the history list.

    If the value is 0, 
       **commands are not saved** in the history list. 

    Numeric values less than zero result in 
       every command being saved on the history list (there is no limit). 

So for an infinite history list, make:
HISTSIZE=(some number less than 0)

HISTFILESIZE 
    The maximum number of lines contained in the history file. 

    When this variable is assigned a value, 
        the history file is truncated, if necessary, 
        to contain no more than that number of lines 
        by removing the oldest entries. 

        The history file is also truncated to this size after 
        writing it when a shell exits. 

    If the value is 0, 
        **the history file is truncated to zero size.** 

    Non-numeric values and numeric values less than zero 
        inhibit truncation. 

So for an infinite .bash_history history file, make:
HISTFILESIZE=(some number less than 0)

18

As mentioned by @Michal Przybylowicz, these files seem to be ignored in Xubuntu (and Lubuntu) sometimes. If so, you could instead write the lines

export HISTSIZE=10000
export HISTFILESIZE=10000

to /etc/bash.bashrc. This will change these environment variables' values globally.

In78
  • 623
serv-inc
  • 3,059
  • 2
    Your two lines could be reduced to just HISTSIZE=10000 since export is not necessary for Bash variables in .bashrc and because if HISTFILESIZE is unset, it takes its value from HISTSIZE. From man bash: "The shell sets the default value to the value of HISTSIZE after reading any startup files." – Matthias Braun May 27 '23 at 09:02