如果您打开了10个xterms,那么是否可以以某种方式搜索所有bash历史记录?
我可以
history|grep something
Run Code Online (Sandbox Code Playgroud)
在每一个单独但我有时想避免这一点.
我将假设这些xterm窗口都是针对相同的用户ID,并且都在同一主机上.如果它们不是同一个用户,则必须更改其历史文件位置以使用相同的历史文件.如果您需要这样做,请参阅此主题:https://superuser.com/questions/760830/how-do-i-change-the-bash-history-file-location
但是你要遇到的主要问题是bash只.bash_history在shell关闭时写入其历史记录.但是,您可以编辑自己.bashrc以立即编写最新命令.bash_history,如下所示:
# When the shell exits, append to the history file instead of overwriting i
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"
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅此链接:https://unix.stackexchange.com/questions/1288/preserve-bash-history-in-multiple-terminal-windows