Sunday, July 24

How do I display shell command history date and time in Linux

If the HISTTIMEFORMAT is set, the time stamp information associated with each history entry is written to the history file, marked with the history comment character.

  495   vi /etc/xinetd.d/krb5-telnet
  496  /etc/rc.d/init.d/xinetd restart
  497  telnet linux2
  498  hsitory
  499  history
[root@linux1 ~]#

[root@linux1 ~]# HISTTIMEFORMAT="%d/%m/%y %T "

Verify

  495  27/05/16 14:59:37  vi /etc/xinetd.d/krb5-telnet
  496  27/05/16 14:59:37 /etc/rc.d/init.d/xinetd restart
  497  27/05/16 14:59:37 telnet linux2
  498  27/05/16 15:41:32 hsitory
  499  27/05/16 15:41:34 history
  500  27/05/16 15:41:55 HISTTIMEFORMAT="%d/%m/%y %T "
  501  27/05/16 15:42:30 history
[root@linux1 ~]#

You can set this in bash_profile. Logout back in required.
$ echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile

Some other important History related commands

Check history command (maximum number of line history file can carry). Check also /etc/profile for size as well.
[root@linux1 ~]# echo $HISTSIZE

Make history size to 2000 lines
[root@linux1 ~]# export HISTSIZE=2000

Verify
[root@linux1 ~]# echo $HISTSIZE

If you want to disable history all together and don’t want bash shell to remember the commands you’ve typed, set the HISTSIZE to 0 as shown below.
# export HISTSIZE=0