【问题标题】:How to quickly delete shell command that is already been typed in console? [closed]如何快速删除已经在控制台输入的shell命令? [关闭]
【发布时间】:2015-08-13 17:04:07
【问题描述】:

有时,我会在我的控制台中输入一些 shell 命令,然后再决定不执行它。例如,我在控制台终端中输入以下内容:

sudo rm -r /   # not yet committed! Thank God

好吧,我意识到这有点愚蠢,并决定在真正执行之前删除。

但是,我很懒,我不想按 delete 并等待退格光标。事实上,这种情况对我来说是很正常的。

我想用尽可能少的键盘按下来快速删除 shell 命令。有什么解决办法吗?

谢谢~

【问题讨论】:

标签: shell


【解决方案1】:

Ctrl+uCtrl+k 是您要查找的内容:

 Ctrl + k    # Cut the Line after the cursor to the clipboard.
 Ctrl + u    # Cut/delete the Line before the cursor to the clipboard.

您可能想尝试的其他常用快捷键:

 Ctrl + w    # Cut the Word before the cursor to the clipboard.
 Ctrl + y    # Paste the last thing to be cut (yank)
 Ctrl + a    # Go to the beginning of the line (Home)
 Ctrl + e    # Go to the End of the line (End)
 Alt + b     # Back (left) one word
 Alt + f     # Forward (right) one word
 Ctrl + f    # Forward one character
 Ctrl + b    # Backward one character
 Alt + d     # Delete the Word after the cursor.
 Ctrl + d    # Delete character under the cursor
 Ctrl + h    # Delete character before the cursor (Backspace)

和往常一样,我建议你去Bash Keyboard Shortcuts 学习更高级的 Bash 技能。

【讨论】:

  • 有趣的是,您如何设法列出这么多键盘快捷键,但您却忽略了 ctrl + c,这可能是 OP 正在寻找的(也由 kirbyfan64sos 指出)。跨度>
  • 因为 OP 正在寻找一种“快速删除 shell 命令”而不是“快速中止 shell 命令”的方法,所以我相信 Ctrl + uCtrl + k 是 OP 想要的,不是Ctrl + c
  • 很公平,但将其添加到额外命令列表中可能仍然有用。顺便说一句,不错的帖子,我一定会阅读这些键盘快捷键!
  • 请注意,在许多系统上,到目前为止,还有一个终端“kill”字符会终止输入。通常,这就是 control-X。您可以通过stty -a 查询。这适用于任何不主动修改终端控件的程序。
猜你喜欢
  • 2017-02-25
  • 2021-02-12
  • 1970-01-01
  • 1970-01-01
  • 2018-12-20
  • 1970-01-01
  • 2011-02-14
  • 1970-01-01
  • 2012-06-11
相关资源
最近更新 更多