Under Construction

Working with the bash History

Almost all shells offer a history. This means the shell remembers past commands and offers access to these commands. This saves time, since it often happens that a command needs to be executed again and the command then does not have to be typed in again. The easiest way to access previous commands in bash is to use the cursor up and cursor down keys. However, the options offered by bash to access the history go far beyond this and are not as well known to many users as using the cursor keys. The following will therefore deal with some of these further possibilities.

The history mechanism is activated by default in an interactive bash. The history of previous commands can be displayed with the builtin command history:

[user01@aixe01 ~]$ history
    1  ls -l /usr
    2  vi sample.txt
    3  ls -l sample.txt
    4  cat sample.txt
    5  cp sample.txt sample.txt.bak
    6  history
[user01@aixe01 ~]$

The previous commands are numbered consecutively. By default, the history is stored in the file ~/.bash_history.