我在 BASH 中输入了一个长命令,但就在我输入命令时,我发现我拼错了命令或参数。我希望光标使用就地搜索转到我拼错的参数或命令,而不是按箭头键转到特定的命令或参数。
例如
ls *.txt | grep -e 'foo' >> list_of_text_files_containing_foo.txt
Run Code Online (Sandbox Code Playgroud)
我想改变foo在grep来bar通过查找和替换foo到bar命令里面没有击中箭头键。有没有办法改变所有出现的footo bar。
您可能对最后一个命令中的 bash 快速替换感兴趣:
!!:gs/old/new
Run Code Online (Sandbox Code Playgroud)
例子:
$ ls *.txt | grep -e 'foo' >> list_of_text_files_containing_foo.txt
$ !!:gs/foo/bar
ls *.txt | grep -e 'bar' >> list_of_text_files_containing_bar.txt
Run Code Online (Sandbox Code Playgroud)
有关 bash 替换的更多信息,请man bash从 3630 行开始阅读。