Bash – How to set the number of commands history recalls

bashcommand history

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.

Best Answer

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.