Re: [SLE] timestamps in bash history
![](https://seccdn.libravatar.org/avatar/3f773ea81891e87ae24e797d72e78163.jpg?s=120&d=mm&r=g)
On Wednesday 08 March 2006 09:53, Kenneth Klein wrote:
So this "variable"? Is that set in .profile? How would I go about seeing what it is? Echo?
Jim Cunning wrote:
On Tuesday 07 March 2006 15:05, Clement Twine wrote:
hi all,
how can one make the history (in bash_history) to include time stamps?
-clem
See 'man bash' -- specifically:
HISTTIMEFORMAT If this variable is set and not null, its value is used as a format string for strftime(3) to print the time stamp associated with each history entry displayed by the history builtin. If this variable is set, time stamps are written to the history file so they may be preserved across shell sessions. 'echo $HISTTIMEFORMAT' will display the current value of the environment variable.
Command history is a bash feature, so you should set it in your ~/.bashrc: HISTTIMEFORMAT='%F %T ' (see 'man strftime') will result in 'history' producing something like this: ..... 348 2006-03-08 10:26:48 HISTTIMEFORMAT='%F %T ' 349 2006-03-08 10:26:59 history | less Note that the lines actually written to .bash_history do not have a directly searchable timestamp, but instead are written as a pair of lines with the first being an integer representing the time, e.g., #1141842419 history | less You can convert the integer to a timestamp by $ perl -e 'print scalar localtime(1141842419), "\n"' Wed Mar 8 10:26:59 2006 Jim
participants (1)
-
Jim Cunning