Bash_history
Getting date-time in bash history: Link to heading
Add to end of .bashrc
shopt -s histappend
PROMPT_COMMAND="history -n; history -a"
unset HISTFILESIZE
export HISTTIMEFORMAT="%F %T > "
export HISTSIZE=2000
Do . .bashrc
from home to re-source (or source path/to/.bashrc
).
Test with history
or Ctrl-R
.
parsing .bash_history Link to heading
.bash_history
now has entries looking like this:
#1733237692
nvim ~/.bash_history
I didn’t know what the hash-number was.. but guessed epoch. That was correct. So parsing can look like this:
Time.at(EPOCH.to_i).to_datetime.strftime('%F %T')
Full example:
require 'date'
HIST_FILE = '/my_home/.bash_history'
ep2dt = ->(ep) { Time.at(ep.to_i).to_datetime.strftime('%F %T')}
File.open(HIST_FILE).each {|ln|
ln =~ /^#(\d+)$/ ? (print ep2dt[$1]) : (puts ' %s' % ln)
}