Set Date and Time for Each Command You Execute in Bash History

Subject:

To set HISTTIMEFORMAT variable temporarily, export it as below on the command line:

$ export HISTTIMEFORMAT='%F %T'

In the export command above, the time stamp format:

  1. %F – expands to full date same, as %Y-%m-%d (year-month-date).
  2. %T – expands to time; same as %H:%M:%S (hour:minute:seconds).

 

However, if you want to configure this variable permanently, open the file ~/.bashrc with your favorite editor:

$ vi ~/.bashrc

And add the line below in it (you mark it with a comment as your own configuration):

#my config export HISTTIMEFORMAT='%F %T'

Save the file and exit, afterwards, run the command below to effect the changes made to the file:

$ source ~/.bashrc

2017-01-16 08:26:47gstlouis