How to Increase Bash History Size

Some valuable or complex commands may not be able to keep in your mind constantly when you need them. In this moment, you can leverage the command history to recall them. But as time goes by, you could lose them due to the size limitation of command history.

The history always keep the most recent command lines in ~/.bash_history. The limitation of size is controlled by $HISTSIZE and default value is 1000 which could be too low for recalling more valuable commands. That’s why you should increase bash history size of commands.

Increase Bash History Size For Personal Setting

You should export the value of HISTSIZE in ~/.bash_profile

Here are the steps:

  1. Open your ~/.bash_profile in vi
  2. Export HISTSIZE into any value larger than 1000

    [@test ~]$ vi ~/.bash_profile


    export HISTSIZE=10000

  3. Take effect immediately

    [@test ~]# . ~/.bash_profile

    [@test ~]# echo $HISTSIZE

    10000

Increase Bash History Size For Global Setting

You should change the value of HISTSIZE in /etc/profile

Here are the steps:

  1. Open /etc/profile in vi
  2. Find a variable called HISTSIZE
  3. Modify the value of HISTSIZE into any value larger than 1000

    [root@test ~]# vi /etc/profile


    #HISTSIZE=1000

    HISTSIZE=10000

  4. Take effect immediately

    [root@test ~]# . /etc/profile

    [root@test ~]# echo $HISTSIZE

    10000

Don’t worry about the growing file size of ~/.bash_history. Even you set 10000, it doesn’t take that much space as you think.


Leave a Reply

Your email address will not be published. Required fields are marked *