83

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 HISEFILESIZE=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?

  • 2
    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 Aug 7 '18 at 1:15
78

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
| improve this answer | |
  • 6
    hisfilesize is in KB? – Patoshi パトシ Jul 31 '14 at 14:21
  • 13
    @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 2:01
  • 2
    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 8: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 at 1:23
53

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)

| improve this answer | |
6

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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