23

I am using bash. To browse my command history I am calling the history command which I believe is calling the Gnu program of the same name. (I don't know if there's a better bash specific way).

In my .bashrc I currently have a line export PROMPT_COMMAND='history -a' to preserve history from my multiple bash sessions I am running.

If I do history I currently only see 524 entries. Is this configurable? I would like to increase this to a much larger number say 2000.

sendmoreinfo
  • 2,573
Gilles
  • 429

4 Answers4

26

First of all, history is the bash specific way, none better. The history command is a bash builtin as you can see by running

$ type history 
history is a shell builtin

Now, the number of commands it remembers is controlled by the HISTSIZE variable. To set it to a larger number add this line to your .profile (for why this is a better place for it than .bashrc, see here):

export HISTSIZE=2000

From now on, history will return the last 2000 commands you ran.

terdon
  • 242,166
5

The HISTSIZE variable dictates how many commands are kept in the running history and HISTFILESIZE determines how many commands from the running history are saved once the shell exits.

Bratchley
  • 16,824
  • 14
  • 67
  • 103
5

Yes, man bash says:

HISTSIZE - The number of commands to remember in the command history

But there is a Readline's variable: history-size

Set the maximum number of history entries saved in the history list. If set to zero, any existing history entries are deleted and no new entries are saved. If set to a value less than zero, the number of history entries is not limited. By default, the number of history entries is not limited.

You can set history-size with HISTSIZE=1000, bind 'set history-size 1000' or with the following line in your ~/.inputrc: set history-size 1000

Examples:

HISTSIZE=1000
bind 'set history-size 0'
echo $HISTSIZE # prints 1000
bind -v | grep history-size # prints set history-size 0
history # prints nothing

bind 'set history-size 0'
HISTSIZE=1000
echo $HISTSIZE # prints 1000
bind -v | grep history-size # prints set history-size 1000
history # prints    13  echo $HISTSIZE\n14  bind -v | grep history-size\n15  history

history-size available since bash-4.0-alpha: CHANGES

Evgeny
  • 5,476
0
For more information, I am adding it. I used ubuntu 18. This worked for me.
$ echo $HISTSIZE
1000
$ echo $HISTFILESIZE
1000
$ echo $HISTFILE

vi /home/siva/.bashrc  # here we need to update the HISTSIZE variable to the required thing.
NOTE: open new terminal and check updated value will bere printed if you run $ echo $HISTSIZE

Reference Link:
https://www.redhat.com/sysadmin/history-command
Kodali444
  • 101