Under Construction

History Entries with Timestamp

By default, the history is displayed in the form history event number followed by the associated command:

[user01@aixe01 ~]$ history
    1  ls -l
    2  hostname
    3  df /
    4  pwd
    5  history
[user01@aixe01 ~]$

Especially with longer histories, it would be useful to see when the individual commands were issued. This can be configured using the bash variable HISTTIMEFORMAT. A format specification can be made here. Percent specifications in the format of strftime(3) can be used. E.g. “%d” for day, “%m” for month and “%y” for year, as well as “%H” for hour, “%M” for minute and “%S” for second. We test the following format string:

[user01@aixe01 ~]$ HISTTIMEFORMAT="%d.%m.%y %H:%M:%S  "
[user01@aixe01 ~]$

The output of the history then contains the appropriate timestamp before each command, as desired:

[user01@aixe01 ~]$ history
   1  24.04.22 14:37:17  ls -l
   2  24.04.22 14:37:17  hostname
   3  24.04.22 14:37:17  df /
   4  24.04.22 14:37:17  pwd
   5  24.04.22 14:37:20  history
   6  24.04.22 14:39:59  HISTTIMEFORMAT="%d.%m.%y %H:%M:%S  "
   7  24.04.22 15:03:29  history
[user01@aixe01 ~]$

You can try different formats online by changing the HISTTIMEFORMAT variable. If you are satisfied with the result, you should store the desired setting in one of the bash startup files. As before, we use ~/.bashrc:

[user01@aixe01 ~]$ cat ~/.bashrc

HISTTIMEFORMAT="%d.%m.%y %H:%M:%S  "

[usr01@aixe01 ~]$