Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
任何人都可以解释以下内容吗?当我使用 ssh 远程执行历史记录时,不会产生任何输出,甚至其他远程命令也会产生输出,并且该机器上有历史记录。
ssh host 'history | tail' # produces no output ssh host 'echo foo | tail' # produces 'foo' as output ssh host > history | tail # produces expected output
非交互式 shell 不会加载历史记录。您可以使用tail历史记录文件 ( ~/.bash_history) 或打开历史记录并加载它。
tail
~/.bash_history
set -o history history -r
从远程主机执行此操作所需的完整命令如下:
ssh host 'HISTFILE=~/.bash_history; history -r; history' | tail