ale*_*ale 78 linux bash command-line
只是一个提高我的bash
技能的问题.我总是这样做:
$ history | grep some_long_command
...
...
123 some_long_command1.........
124 some_long_command2.........
...
Run Code Online (Sandbox Code Playgroud)
然后,我可以通过执行命令运行命令:
!123
但是,我经常想这样做:
some_long_command1foobar
Run Code Online (Sandbox Code Playgroud)
即在我运行它之前更改命令.您可以使用bash来运行此命令:
#some_long_command1
所以它得到了评论.
然后,我不必使用鼠标突出显示命令,编辑它然后运行它(我可以使用键盘 - 更快).
我想我可以写一个脚本来做它,但可能已经在某个地方内置了功能......?
谢谢.
Miq*_*uel 138
我建议您使用ctrl+r
并开始键入该命令,而不是使用history 命令.当你按下箭头键就像去修改它一样,它将退出自动完成识别,并允许你在运行之前进行编辑.
更新:此外,如果您想循环包含您刚输入的字符串的不同命令,请继续按下 ctrl+r
joe*_*t45 59
实际上,您只需附加:p
命令即可打印它而无需实际运行它.例如:
$ ls -la
$ !!:p
Run Code Online (Sandbox Code Playgroud)
将ls -la
在不运行前打印出上一个命令,您只需按↑(向上)查找并编辑它即可.
你也可以
!123:p
Run Code Online (Sandbox Code Playgroud)
打印出123rd命令作为上一个命令.
Pri*_*ley 18
您还可以尝试使用fc
命令编辑历史记录中的命令.
FC是UNIX上的标准程序,该目录或编辑和重新执行,先前命令输入到交互壳.fc是bash shell中的内置 命令; help fc将显示使用信息.
除了反向增量搜索(Ctrl+ R),我们还有一些更多的bash快捷方式:
来自man bash
:
previous-history (C-p) Fetch the previous command from the history list, moving back in the list. next-history (C-n) Fetch the next command from the history list, moving forward in the list. beginning-of-history (M-<) Move to the first line in the history. end-of-history (M->) Move to the end of the input history, i.e., the line currently being entered. reverse-search-history (C-r) Search backward starting at the current line and moving 'up' through the history as necessary. This is an incremental search. forward-search-history (C-s) Search forward starting at the current line and moving 'down' through the history as necessary. This is an incremental search. non-incremental-reverse-search-history (M-p) Search backward through the history starting at the current line using a non-incremental search for a string supplied by the user. non-incremental-forward-search-history (M-n) Search forward through the history using a non-incremental search for a string supplied by the user. yank-nth-arg (M-C-y) Insert the first argument to the previous command (usually the second word on the previous line) at point. With an argument n, insert the nth word from the previous command (the words in the previous command begin with word 0). A negative argument inserts the nth word from the end of the previous command. Once the argument n is computed, the argument is extracted as if the "!n" history expansion had been specified. yank-last-arg (M-., M-_) Insert the last argument to the previous command (the last word of the previous history entry). With an argument, behave exactly like yank-nth-arg. Successive calls to yank-last-arg move back through the history list, inserting the last argument of each line in turn. The history expansion facilities are used to extract the last argument, as if the "!$" history expansion had been specified. shell-expand-line (M-C-e) Expand the line as the shell does. This performs alias and history expansion as well as all of the shell word expansions. See HISTORY EXPANSION below for a description of history expansion. history-expand-line (M-^) Perform history expansion on the current line. See HISTORY EXPANSION below for a description of history expansion. insert-last-argument (M-., M-_) A synonym for yank-last-arg. operate-and-get-next (C-o) Accept the current line for execution and fetch the next line relative to the current line from the history for editing. Any argument is ignored. edit-and-execute-command (C-xC-e) Invoke an editor on the current command line, and execute the result as shell commands.
归档时间: |
|
查看次数: |
47975 次 |
最近记录: |