I would like to keep timestamps on the commands logged in my Bash $HISTFILE, is it possible?
I did not manage to set it up using man bash
as an information source.
My other options are as follows:
function thebanana() {
local -r -a bash_commands=(
"ls"
# ... more coconut commands
)
for bash_command in "${bash_commands[@]}"; do
printf "${bash_command}"
printf ":"
done
}
export HISTFILE=banana
export HISTIGNORE="$(thebanana)"
export HISTSIZE=999999
export HISTFILESIZE=999999999
export HISTCONTROL=ignoredups:erasedups
I should have mentioned I am on OS X Mountain Lion (sigh). uname -a
gives me:
Darwin CoconutMac.local 12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64
and echo $BASH_VERSION
gives me:
3.2.48(1)-release
Tried adding this:
export HISTTIMEFORMAT='%b %d %I:%M:%S %p '
and it only prefixes this kind of timestamps to commands:
#1349057791
I try echoing back the variable (echo $HISTTIMEFORMAT
), it has the right value.
Interesting!
I even removed .profile completely to debug this. Still only funny timestamps:
#1349058320
I don't know how to further troubleshoot this... :(
Solution: I was using a script that reads the $HISTFILE directly, not the history built-in so the epoch-based timestamp (secs since Coordinated Universal Time (UTC) of January 1, 1970) was not being translated using the date formatting string. Plain-old history
works fine, I'll use that instead.
HISTTIMEFORMAT
?