Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

bash - 如何清除/删除终端中的当前行?(How do I clear/delete the current line in terminal?)

If I'm using terminal and typing in a line of text for a command, is there a hotkey or any way to clear/delete that line?

(如果我正在使用终端并为命令输入一行文本,是否有热键或任何方式来清除/删除该行?)

For example, if my current line/command is something really long like:

(例如,如果我当前的行/命令非常像:)

> git log --graph --all --blah..uh oh i want to cancel and clear this line <cursor is here now>

Is there a hotkey or command to go from the above to:

(是否有热键或命令从上面到:)

>

?

(?)

Usually I will press the key, and if my current line is a brand new one on the history, that will clear it.

(通常我会按键,如果我的当前行是历史上的全新行,那将清除它。)

But if I'm going through my command history via the key and start editing or using those commands, will only change the prompt to the next newest command in history, so it doesn't work here unless I press multiple times.

(但是如果我通过键浏览我的命令历史并开始编辑或使用这些命令, 只会将提示更改为历史记录中的下一个最新命令,因此除非我多次按↓,否则它不起作用。)

  ask by triad translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use Ctrl + U to clear up to the beginning.

(您可以使用Ctrl + U清除开头。)

You can use Ctrl + W to delete just a word.

(您可以使用Ctrl + W删除一个单词。)

You can also use Ctrl + C to cancel.

(您也可以使用Ctrl + C取消。)

If you want to keep the history, you can use Alt + Shift + # to make it a comment.

(如果要保留历史记录,可以使用Alt + Shift + 将其作为注释。)


Bash Emacs Editing Mode Cheat Sheet

(Bash Emacs编辑模式备忘单)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...