Hack 50. Display TIMESTAMP in history using HISTTIMEFORMAT

by Ramesh

Typically when you type history from command line, it displays the command# and the command. For auditing purpose, it may be beneficial to display the timestamp along with the command as shown below.

  1. # export HISTTIMEFORMAT=’%F %T ‘
  2.  
  3. # history | more
  4. 1 2008-08-05 19:02:39 service network restart
  5. 2 2008-08-05 19:02:39 exit
  6. 3 2008-08-05 19:02:39 id
  7. 4 2008-08-05 19:02:39 cat /etc/redhat-release

Note: You can also setup the following alias to view the recent history commands.

  1. alias h1='history 10'
  2. alias h2='history 20'
  3. alias h3='history 30'