Discussion:
[SLE] timestamps in bash history
Clement Twine
2006-03-07 23:05:47 UTC
Permalink
hi all,

how can one make the history (in bash_history) to include time stamps?

-clem
--
Check the headers for your unsubscription address
For additional commands send e-mail to suse-linux-e-***@suse.com
Also check the archives at http://lists.suse.com
Please read the FAQs: suse-linux-e-***@suse.com
Jim Cunning
2006-03-08 17:09:52 UTC
Permalink
Post by Clement Twine
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.
--
Check the headers for your unsubscription address
For additional commands send e-mail to suse-linux-e-***@suse.com
Also check the archives at http://lists.suse.com
Please read the FAQs: suse-linux-e-***@suse.com
Jim Cunning
2006-03-08 18:50:09 UTC
Permalink
So this "variable"? Is that set in .profile? How would I go about seeing
what it is? Echo?
Post by Jim Cunning
Post by Clement Twine
hi all,
how can one make the history (in bash_history) to include time stamps?
-clem
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
--
Check the headers for your unsubscription address
For additional commands send e-mail to suse-linux-e-***@suse.com
Also check the archives at http://lists.suse.com
Please read the FAQs: suse-linux-e-***@suse.com
Jim Cunning
2006-03-09 19:37:11 UTC
Permalink
On Thursday 09 March 2006 10:58, Kenneth Klein wrote:
[...]
OK, I gave up on getting it to work on the mac os x. I have SLES-9
[...]
I think it is 9.1, how can I display?
cat /etc/SuSE-release
I tried the method of exporting the variable. Still no joy.
Then I can only conclude (not unreasonably) that bash on OS X is built with
different options than on SuSE. I have had no reason to examine the bash
source, so don't know whether history timestamps can be omitted when it is
built.

Jim
--
Check the headers for your unsubscription address
For additional commands send e-mail to suse-linux-e-***@suse.com
Also check the archives at http://lists.suse.com
Please read the FAQs: suse-linux-e-***@suse.com
Continue reading on narkive:
Loading...