Tmux 历史未保留

Kev*_*tin 5 bash tmux

我遇到一个问题,当我退出 tmux 会话时,找不到在 tmux 终端内运行的命令。可以吗,有人帮忙吗?

tmux- 使用此命令运行 tmux 会话

echo "Hello"- 在 tmux 会话中使用此命令

history- 在这种情况下echo "Hello"命令存在。

exit- 使用它退出 tmux 会话

history- 从 tmux 会话退出后运行此命令

运行此命令后,我无法获取echo "Hello"在 tmux 会话中使用的命令。

van*_*ium 6

退出终端并重新启动它。现在,history将向您展示所有这些命令,都tmux像以前一样来自内部。

.bash_history仅当您退出会话时,会话历史记录才会提交到文件中。当您启动新会话时,.bash_history将读取 且该命令将可用。它这样工作的原因是它允许单独评估每个会话的历史记录。

可以将您的终端配置为立即发出所有会话历史记录中可用的命令。

这里

将以下内容添加到您的 ~/.bashrc 中:

# Avoid duplicates
HISTCONTROL=ignoredups:erasedups # Ubuntu default is ignoreboth
# When the shell exits, append to the history file instead of overwriting it
shopt -s histappend  # In Ubuntu this is already set by default

# After each command, append to the history file and reread it
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"
Run Code Online (Sandbox Code Playgroud)

在此处了解有关 HISTCONTROL 变量的更多信息。

在默认的 Ubuntu 安装中,事实上,单独使用这个命令就可以了:

PROMPT_COMMAND="history -a; history -c; history -r"
Run Code Online (Sandbox Code Playgroud)

请注意,“刷新”提示后,来自不同会话的任何新命令都将在您的会话中可用:创建提示后,历史记录就会更新。