Under Construction

Editing the History

Entries in the history list are automatically made by bash when the history functionality is activated. However, the user can subsequently edit this history list to a limited extent.

We start with the following history:

[user01@aixe01 ~]$ history
    1  ls -l
    2  ls -l
    3  hostname
    4  df /
    5  pwd
    6  cd /usr/bin
    7  ls
    8  ls -l g*
    9  cd
[user01@aixe01 ~]$

Individual entries in the history list can be deleted using “history -d” (delete). To do this, simply enter the number of the command as an argument. As an example, we delete the commands with the number 2 (“ls –l”) and 5 (“pwd”) from the history list:

[user01@aixe01 ~]$ history -d 2
[user01@aixe01 ~]$ history
    1  ls -l
    2  hostname
    3  df /
    4  pwd
    5  cd /usr/bin
    6  ls
    7  ls -l g*
    8  cd
[user01@aixe01 ~]$

It should be noted that later commands then move up accordingly in the numbering scheme. The command “pwd” now has the number 4 and no longer the number 5 as before. Accordingly, the number 4 must be specified with “history -d” in order to delete the pwd command from the history list:

[user01@aixe01 ~]$ history -d 4
[user01@aixe01 ~]$ history
    1  ls -l
    2  hostname
    3  df /
    4  cd /usr/bin
    5  ls
    6  ls -l g*
    7  cd
[user01@aixe01 ~]$

Of course, you can ask yourself why you should delete commands from the history list at all? As will be shown in the next chapter, the history can also be saved manually in any file. For example, you could use the history to document the procedure for a specific task and then save it in a separate file.

If you take up the example given, recording the work steps of a task, you probably want to start with an empty history. The history command offers the “-c” (clear) option for this purpose, with which the history can be completely emptied:

[user01@aixe01 ~]$ history -c
[user01@aixe01 ~]$ history
[user01@aixe01 ~]$

The options described, allow the internal history of bash to be edited in a rudimentary manner. However, no further options are provided for editing. And, this is usually not necessary, since the history can be edited with an editor as soon as it has been saved in a file.