I set ~/.bash_profile some time ago to have more than 500 lines length but seems system can't catch this.

Do you know why?

> nano -w ~/.bash_profile
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced

> history | wc -l

3 Answers 3


You also need to set HISTSIZE=10000000.

HISTFILESIZE determines the number of lines to keep in the history file while HISTSIZE determines the number of lines to keep in memory. Both default to 500

Execute echo $HISTFILESIZE $HISTSIZE before you make the change and then again after. You should see 10000000 500 first then 10000000 10000000 after.

  • 2
    is the export keyword not required? Something like export HISTSIZE=1000000 Commented May 29, 2020 at 11:35
  • 4
    @firstpostcommenter Only if you want to make the variable known to processes launched from the shell
    – nohillside
    Commented May 29, 2020 at 12:06

You need to export HISTSIZE and HISTFILESIZE environment variables in your ~/.bash_profile file.

Add following lines in your ~/.bash_profile:

# history size
export HISTFILESIZE=1000000
export HISTSIZE=1000000


All you need to do is set HISTSIZE in your bash profile (~/.bash_profile). You can leave HISTFILESIZE unset. This will configure both the in-memory history and the file-based history.

# Saves 10 million lines in memory and in the bash history file.

Explanation, additional information.

The problem is HISTFILESIZE only sets the maximum history stored to file when you startup a session. HISTSIZE is what determines how many lines get saved at the end of a session. If HISTFILESIZE is larger than your HISTSIZE, you'll never see more than your HISTSIZE because the file is getting overwritten with HISTSIZE commands (unless you set history to append, but that is a separate topic: look up histappend in shell builtin commands for that).

This is the reason you're seeing no effect. With HISTSIZE at default (probably 500) your history file is always getting overwritten by the most recent $HISTSIZE commands. Anything older (which could potentially grow the list past $HISTSIZE) is wiped away.

For most cases there's no need to set HISTFILESIZE independently of HISTSIZE.

HISTSIZE determines how many lines will get written to the history file. The command list is truncated upon exit, before writing to the history file, keeping N most recent lines. By default, this list overwrites the history file.

HISTFILESIZE determines how large the history file (in lines) can be. The file gets truncated upon startup, keeping N most recent lines. In addition, the history file is potentially truncated whenever HISTFILESIZE is set.

Finally, although it appears to be undocumented, BASH sets HISTFILESIZE based on HISTSIZE if HISTSIZE is set during startup. I've tried this out on macOS, and a few varieties of Ubuntu, and the behavior is consistent. If you set HISTSIZE in a launch file (not via the command line by any means), HISTFILESIZE will be set to match. (Try it yourself: set HISTSIZE to some arbitarily large value in .bash_profile, exit and start a new terminal, then echo $HISTSIZE $HISTFILESIZE and you'll find them matching.)

As a result, there's no reason to touch HISTFILESIZE unless you want different values, and the uses cases to have different values are rare (and typically involve more history customization settings to get something useful).

  • 2
    You are correct Zim. The Bash source code shows that it will just set HISTFILESIZE to HISTSIZE if HISTFILESIZE is unset. git.savannah.gnu.org/cgit/bash.git/tree/…
    – robert
    Commented Oct 1, 2019 at 18:03
  • 1
    @robert Tried this on macOS Catalina v 10.15.7 GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19). I still got only 21 lines worth of history. Can this be overwritten incase of low disc space?
    – ilam engl
    Commented Feb 2, 2022 at 15:10
  • @ilamengl I don't understand the question... so you edited these variables but it doesn't add more than 21 lines of history? Are you out of disk space?
    – robert
    Commented Feb 17, 2023 at 17:39
  • 1
    @robert yep was out of disk space :/ should I delete the comment from feb 2. 2022 to keep the thread clean?
    – ilam engl
    Commented Apr 4, 2023 at 8:21
  • No, you're good, just wanted to know the root cause, ty.
    – robert
    Commented Apr 7, 2023 at 7:47

You must log in to answer this question.

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