bat*_*man 171 command-line shortcut-keys
我几乎在所有任务中都使用终端。假设我输入了一个像这样的巨大命令:
sudo a-huge-command
Run Code Online (Sandbox Code Playgroud)
使用单个快捷方式删除整个命令而不是继续backspace按键的最简单方法是什么?
我是一名 Ubuntu 新手,希望以专业的方式使用 Ubuntu。
dev*_*av2 112
Ctrl+ U应该可以帮助你。
以下是可用的其余选项。从这里抓起
UNIX 理解几个控制键命令,即您通过按住控制键 (ctrl) 并敲击第二个键来输入的命令
CTRL+ S- 冻结屏幕并停止屏幕上的任何显示(相当于无滚动键)(有时需要一些时间才能工作)
CTRL+ Q- 取消冻结屏幕并让屏幕显示继续
CTRL+ C- 中断正在运行的程序
CTRL+ \- 与 CTRL - C 相同但更强(当终端没有响应时使用)
CTRL+ Z- 暂停正在运行的程序(使用 fg 命令来继续程序,参见 s$
CTRL+ H- 删除最后输入的字符
CTRL+ W- 删除最后输入的单词
CTRL+ U- 删除输入的最后一行
CTRL+ R- 从历史中搜索文本
CTRL+ D- 结束许多 UNIX 程序的文本输入,包括 mail 和 write。
笔记:
当我们使用CTRL+W或CTRL+删除时U,我们也在执行(编辑)“剪切”(拉入)操作(删除并存储在缓冲区/剪贴板中)。要在缓冲区/剪贴板中粘贴(拉出)字符串,请使用CTRL+ Y。
Exe*_*n-G 60
我通常使用Alt+ Backspace。如果您正在使用bash,这将让你删除,直到前一个特殊字符(/,;,等)。如果您正在使用zsh,它也会删除斜线和分号。它比仅仅击中要快得多Backspace。
在 中bash,这与Ctrl+ 的不同之处w在于Ctrl+w删除前一个单词,而Alt+Backspace删除直到找到前一个特殊字符。在 中zsh,两个组合键都做同样的事情
Ora*_*Dog 36
以下是可用于shell的键盘快捷键列表bash。
Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + L Clears the Screen, similar to the clear command
Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H Same as backspace
Ctrl + R Lets you search through previously used commands
Ctrl + C Kill whatever you are running or start a new prompt
Ctrl + D Exit the current shell
Ctrl + Z Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + W Delete the word before the cursor
Ctrl + K Clear the line after the cursor
Ctrl + T Swap the last two characters before the cursor
Esc + T Swap the last two words before the cursor
Alt + F Move cursor forward one word on the current line
Alt + B Move cursor backward one word on the current line
Tab Auto-complete files and folder names
Run Code Online (Sandbox Code Playgroud)
您想要做的是通过行尾的Ctrl+C或Ctrl+来实现U。
Sno*_*all 24
Alt+ #(即Alt+ Shift+ 3)将注释掉当前命令并在下一行继续。
例如,如果您键入t, e, s, t, Alt+ #,您将得到:
you@computer$ #test
you@computer$
Run Code Online (Sandbox Code Playgroud)
如果要恢复旧命令,可以按向上箭头并删除哈希字符(Up、Home、Delete或Up、Ctrl+ A、Delete)。
我认为这是GNU Readline的一个特性,因为它适用于 Bash、Python 和 MySQL。
Vil*_*kas 22
Ctrl+ C- 除了中断正在运行的命令之外,它还可以用于“中断”您的命令行输入。
与 Ctrl+ 相比U,您仍然会看到您输入的内容,但您的光标将跳到新行,您将获得一个空的命令行提示符。
小智 8
Bash的readline快捷键Ctrl+ X+E是非常有用的确,当你在命令行工作。如果您正在输入一个长命令并决定要在默认文本编辑器中打开它,您所要做的就是使用快捷方式。
它利用了 Bash 的readline库,这个特殊的快捷方式称为edit-and-execute-command. 您可以通过将设置默认的编辑器export EDITOR="/usr/bin/vi"中~/.bashrc或~/.bash_aliases。
输入bind -P以查看您当前的readline绑定并参考man readline或Ubuntu 联机帮助页以获取更多信息。