134

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?

1
  • 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 Aug 7, 2018 at 1:15

3 Answers 3

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
6
  • 6
    hisfilesize is in KB? Jul 31, 2014 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, 2015 at 2:01
  • 3
    This does not work for some reason on XFCE Terminal Dec 30, 2015 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, 2018 at 8:40
  • 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." May 27, 2023 at 8: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)

17

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.

1
  • 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." May 27, 2023 at 9:02

You must log in to answer this question.

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