liunx多终端history命令实时同步

艺帆风顺 发布于 2025-04-03 21 次阅读


1. 显示时间

export HISTTIMEFORMAT="%F %T "

2. 显示历史命令条目数以及历存放史命令文件大小

HISTFILESIZE=100000
HISTSIZE=10000

3. 终端命令追加

# append to history, don't overwrite it
shopt -s histappend

4. 多终端实时同步

# Save and reload the history after each command finishes
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

TODO

#### Avoid duplicates
export HISTCONTROL=ignoredups:erasedups
#### When the shell exits, append to the history file instead of overwriting it
shopt -s histappend

#### After each command, append to the history file and reread it
export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'n'}history -a; history -c; history -r"
版权声明:本文内容来自CSDN:筑梦之人,遵循CC 4.0 BY-SA版权协议上原文接及本声明。本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行可。原文链接:https://blog.csdn.net/qq_31437583/article/details/52859188如有涉及到侵权,请联系,将立即予以删除处理。在此特别鸣谢原作者的创作。此篇文章的所有版权归原作者所有,与本公众号无关,商业转载建议请联系原作者,非商业转载请注明出处。