是否有使用上一个命令(不是 cd、ls 或 echo)的参数重新运行命令的快捷方式

kon*_*qui 2 command-line bash command-history

使用以下内容搜索传递的日志文件:

cat /path/to/logfile | grep -iEw 'some-ip-address-here|correspondig-mac-adress-here'

这给了我到目前为止所有通过的日志行,所以我可以看到已经发生了什么。现在,我也想看看发生了什么事情,所以我需要换cattail -f给我这个:

tail -f /path/to/logfile | grep -iEw 'some-ip-address-here|correspondig-mac-adress-here'

Wie*_*and 5

您可以使用!!:*来引用除最后一个命令行的第零个以外的所有单词。

!!指的是前一个命令,:将事件规范与单词指示符分开,*指除第零个以外的所有词。

这是来自HISTORY EXPANSIONbash(1)的部分。

wieland@host in ~» cat foo | grep bar
bar
wieland@host in ~» tail -f !!:*
tail -f foo | grep bar
bar
Run Code Online (Sandbox Code Playgroud)

您还可以在^string1^string2^重复最后一个命令的地方使用快速替换,替换string1string2

wieland@host in ~» cat foo | grep bar
bar
wieland@host in ~» ^cat^tail -f
tail -f foo | grep bar
bar
Run Code Online (Sandbox Code Playgroud)