有两个终端窗口 - 终端 A 和终端 B。
我输入了一个很长很长的命令来在 A 上做一些事情。
然后我想在 B 上执行相同的命令。
但我不想再次输入它,也不想拖动复制粘贴,因为它很长。
最好(最快)的方法是什么?
在源终端中写出您的历史记录:
history -a
Run Code Online (Sandbox Code Playgroud)
然后将其加载到目标终端中:
history -r
Run Code Online (Sandbox Code Playgroud)
如果您之间没有执行任何操作,则 long long 命令应该是倒数第三个命令:
!-3
Run Code Online (Sandbox Code Playgroud)
或者你可以做history,记下 long long 命令的数量(比如 2365),然后做:
!2365
Run Code Online (Sandbox Code Playgroud)
来自help history:
-a append history lines from this session to the history file
-r read the history file and append the contents to the history
list
-w write the current history to the history file
and append them to the history list
Run Code Online (Sandbox Code Playgroud)
您还可以使用history -n代替-r:
-n read all history lines not already read from the history file
Run Code Online (Sandbox Code Playgroud)
另请参阅此 SO 问题。