How to Enable timestamp for History Command

Here is a way of how you can see a timestamp for executed command when using "history" command in Linux.


You can export HISTTIMEFORMAT variable, with appropriate date formatting.

For example you can use:   (update in /etc/bashrc or /etc/profile )

export HISTTIMEFORMAT='%F %H:%M:%S '

In this case the history command will give you an output like this: 

[root@amitmaheshwari.in ] # export HISTTIMEFORMAT='%F %H:%M:%S '

[root@amitmaheshwari.in ] # history | head

    1  2014-05-13 02:41:45 rpm -qa | less
    2  2014-05-13 02:41:45 rpm -qa | grep -i net
    3  2014-05-13 02:41:45 ifconfig
    4  2014-05-13 02:41:45 ifup eth0
    5  2014-05-13 02:41:45 ifconfig
    6  2014-05-13 02:41:45 ping 10.0.0.1
    7  2014-05-13 02:41:45 ping 10.0.15.8
    8  2014-05-13 02:41:45 netstat -antp
    9  2014-05-13 02:41:45 hostname
   10  2014-05-13 02:41:45 init 0