7

Tip #534   Adding times to the history

Typically when one types the history command, it displays the command number and the command. For auditing purposes it would be helpful to display the timestamp as well. To do so we need to set the environmental variable HISTTIMEFORMAT.

HISTTIMEFORMAT supports format strings of strftime.

Some important format strings:

%T Replaced by the time ( %H : %M : %S )
%F Equivalent to %Y - %m - %d

$ export HISTTIMEFORMAT='%F %T '

Now execute
$ history

it will print the command line history with corresponding timestamp when the command was executed, such as:
499  2009-02-11 18:20:52 ls