How to set OR enable Timestamp for the previously executed commands in Linux?

Linux provides a command called “history” to view the previously executed commands on shell. By default, the “history” command display only the commands that were executed but not the date and time when they were executed.

To display the time and date of the previously executed commands, you need to set the “HISTTIMEFORMAT” variable. The variable has to be set in the users profile file so to take effect on each session.

To set the “HISTTIMEFORMAT” variable, SSH to your server and execute:

# export HISTTIMEFORMAT="[%F] [%T] "

You can also insert the above line at the end of the .bash_profile file

# vi /root/.bash_profile

Once the file is saved, open a new SSH session and execute the ‘history’ command to view the timestamp of the previously executed commands.

For example:

root@server [~]# history
 1068  [2010-08-05] [07:17:04] ps -auxf
 1069  [2010-08-05] [07:17:06] top c
 1070  [2010-08-05] [07:17:35] ll
 1071  [2010-08-05] [07:37:51] ls -la
 1072  [2010-08-05] [07:41:37] cat /root/.bash_profile
 1073  [2010-08-05] [07:41:47] cd

The commands in the above output is just an example.

This entry was posted on Thursday, August 5th, 2010 and is filed under Linux Administration. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

3 Responses to “How to set OR enable Timestamp for the previously executed commands in Linux?”

  1. chavete88

    this variable give me the next mensage -bash: HISTTIMEFORMAT: readonly variable

  2. chavete88

    i forgot, on slackware 13.0

  3. admin

    The variable on Slackware may be different. Will email you when I figured it out.