3 ms·
This entire blog post could be reduced to use the HISTFORMAT variable, which the author doesn't apparently know about. Put this in your ~/.bashrc: export H
by SEJeff 10y ago
This entire blog post could be reduced to use the HISTFORMAT variable, which the author doesn't apparently know about. Put this in your ~/.bashrc:
export HISTTIMEFORMAT='%Y-%m-%d %H:%M.%S | '
An example of the "history | tail" results:
$ history | tail
50198 2016-05-31 10:15.57 | cd docker
50199 2016-05-31 10:16.03 | cd rpms/
50200 2016-05-31 10:16.11 | scp docker* omniscience:/tmp/
50201 2016-05-31 10:14.06 | screen -ls
50202 2016-05-31 08:33.34 | screen -x
50203 2016-05-31 19:06.53 | grep HIST .bashrc
50204 2016-05-31 19:07.46 | history | tail
50205 2016-05-31 19:08.10 | task ls
50206 2016-05-31 19:08.23 | docker ps -qa
50207 2016-05-31 19:08.30 | history | tail
A few from my bashrc:
$ grep HIST .bashrc
HISTCONTROL=ignoredups:ignorespace
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
export HISTFILESIZE=99999
export HISTSIZE=99999
export HISTTIMEFORMAT='%Y-%m-%d %H:%M.%S | '
export HISTIGNORE="ls:exit:history:[bf]g:jobs"
And then a cronjob that simply backs up the data.
- reptation 10y agothe difference is that the author's version backs up every command to a file as it happens. If you have multiple terminals open, you do not get the same output running "history".
- SEJeff 10y agosomething other than: shopt -s histappend Isn't that exactly what that shell option does?
- LukeShu 10y agoThat does make multiple terminals play nice with eachother, but it's still different, as OP's still flushes to HISTFILE after every command. But, then we can do that with PROMPT_COMMAND='history -a'