Home Linux Tips Linux command line history with timestamp

Who's Online

  • [Bot]
  • [Google]
Now online:
  • 2 guests
  • 2 robots
Latest members:
  • Glasttrarne
  • Nikhilbhave

Statistics

Content View Hits : 15618

Do You Know ?

ESME - External Short Message Entity
Linux command line history with timestamp

History command is a very useful command for the linux administror to list out all the executed commands. It is very useful to find out what commands was executed that broke down the server.


By default the command history could not provides the date time stamp of the commands being executed, that may really narrow down the scope of the user actions that cause the server malfunction.Thankfully there is a way to add timestamps to the bash history since Bash version 3.0, we just need to set environment variable HISTTIMEFORMAT.

HISTTIMEFORMAT takes format string of strftime

export HISTTIMEFORMAT="%F %T "


Put the above command in /etc/bashrc

and execute the bashrc like . /etc/bashrc to implement the changes.

This will print the command line history with corresponding timestamp when the command will execute.

 1000  2009-04-29 23:36:52 netstat -lna
 1001  2009-04-29 23:37:11 history
 1002  2009-04-29 23:39:24 cat /etc/bashrc
 1003  2009-04-29 23:50:35 history

 
 
keywords
job title or skills
location
city, state or zip
Jobs by SimplyHired
Banner