在 bash 中,如何清除当前输入? [英] In bash, how does one clear the current input?
问题描述
假设您在 bash 中开始编写如下命令:
Suppose in bash you start writing a command like:
$ rm -rf /foo/bar/really/long/path/here
然后意识到您根本不想执行此操作.有没有办法通过一两次按键清除输入?
and then realize you don't want to execute this after all. Is there a way to clear the input with one or two keystrokes?
我最近一直在做的是在 echo 之前加上引号并将输入括起来 (Ctrl+A, echo "
, Ctrl+E, "
) 然后按回车键.有没有更快的方法?
What I have been doing lately is prepending echo and enclosing the input in quotes (Ctrl+A, echo "
, Ctrl+E, "
) then hitting enter. Is there a faster way?
推荐答案
按 Ctrl-U 删除光标前的所有内容.删除的命令将存储到缓冲区中.按 Ctrl-Y 粘贴删除的命令.
Press Ctrl-U to delete everything before the cursor. The deleted command will be stored into a buffer. Press Ctrl-Y to paste the deleted command.
(可选:按 End 或 Ctrl-E 先跳到输入的结尾.)
(Optional: Press End or Ctrl-E to jump to the end of the input first.)
或者,按 Ctrl-C 中止您正在输入的内容.
Alternatively, press Ctrl-C to abort what you're typing.
这篇关于在 bash 中,如何清除当前输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!