Under Construction

General Configuration

The history functionality can be turned on or off via the shell option history. By default, the history functionality is enabled for an interactive bash.

Turning on the history functionality:

[user01@aixe01 ~]$ set -o history
[user01@aixe01 ~]$ set -o | grep history
history         on
[user01@aixe01 ~]$

Turning off the history functionality:

[user01@aixe01 ~]$ set +o history
[user01@aixe01 ~]$ set -o | grep history
history         off
[user01@aixe01 ~]$

Note: It is then also no longer possible to access previous commands using the cursor keys!

The functionality of the history expansion using the history character “!” can also be activated or deactivated. There is the shell option histexpand for this purpose.

Activating the history extpansion:

[user01@aixe01 ~]$ set -o histexpand
[user01@aixe01 ~]$ set -o | grep hist
histexpand      on
history         on
[user01@aixe01 ~]$

Turning off history expansion:

[user01@aixe01 ~]$ set +o histexpand
[user01@aixe01 ~]$ set -o | grep hist
histexpand      off
history         on
[user01@aixe01 ~]$

Note: The history expansion is enabled by default for an interactive bash.

In order to keep the history from one session to the next session, the history is saved to a file by default. The file ~/.bash_history is used by default. However, another file can also be used via the shell variable HISTFILE. A maximum of HISTFILESIZE lines are saved in the history file, by default 500. By setting the variable HISTFILESIZE to a different value, a correspondingly different number of commands can be saved.

The file specified in HISTFILE is overwritten by default! If this is not desired and you want to keep existing entries in the file, you can use the histappend shell option. The option is switched off by default:

[user01@aixe01 ~]$ shopt histappend
histappend      off
[user01@aixe01 ~]$

The option can be turned on at any time with the command “shopt –s”:

[user01@aixe01 ~]$ shopt -s histappend
[user01@aixe01 ~]$ shopt histappend
histappend      on
[user01@aixe01 ~]$

Now when bash exits, the current history entries are appended to the existing history file. However, only a maximum of HISTFILESIZE lines can be stored in the history file.

Another configuration option concerns the number of commands in the internal history. For this there is the independent variable HISTSIZE with a default value of 500. This means that a different number of commands can be stored in the internal bash history than in the history file.

As usual, changes to the configuration should be stored in one of the bash startup files, we use the ~/.bashrc file again for this:

[user01@aixe01 ~]$ cat .bashrc

shopt –s histappend

[user01@aixe01 ~]$