20

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.

23

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.

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

4

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.

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.