Linux 终端 Bash 常用快捷键介绍及经验

    xiaoxiao2021-03-25  32

    1. 最重要的自动补全

    命令解释Tab自动补全

    不用多说,自动补全可以节省大量时间

    2. 编辑跳转

    命令解释Ctrl + A跳转到当前行首Ctrl + E跳转到当前行末Alt + F将光标在当前行上向后移动一个单词Alt + B将光标在当前行上向前移动一个单词Ctrl + W删除当前光标前的一个单词Ctrl + K删除当前光标后的内容Ctrl + U清除整行Ctrl + L清屏,类似于 clear 命令Ctrl + H退格,类似于 backspace 键Ctrl + T将当前光标前的两个字符互换位置Esc + T将当前光标前的两个单词互换位置

    Ctrl + W 和 Ctrl + U 相当常用。拼写错是很常见的事。

    Ctrl + L 也不用多说。

    Alt + F 和 Alt + B 敝人也相当常用。这两个键用的是 Alt 而不是 Ctrl 键,所以在 Mac 的终端里会有问题。解决办法是在 偏好设置 - 描述文件 - 键盘 里,将 将 Option 键用作 Meta 键 选项打勾就行了。

    3. 进程相关

    命令解释Ctrl + C终止当前进程Ctrl + Z将当前进程在后台挂起Ctrl + D退出当前 Shell,类似于 exit 命令

    Ctrl + C 是向当前运行的进程发送 SIGINT 信号,终止进程。

    SIGINT - This signal is the same as pressing ctrl-c. On some systems, "delete" + "break" sends the same signal to the process. The process is interrupted and stopped. However, the process can ignore this signal.

    Ctrl + Z 并不结束进程,而是挂起在后台。之后仍然可以通过 fg 命令恢复。对应的信号是 SIGTSTP。

    SIGTSTP - This signal is like pressing ctrl-z. This makes a request to the terminal containing the process to ask the process to stop temporarily. The process can ignore the request.

    4. 搜索使用过的命令(特别推荐)

    命令解释Ctrl + R用于搜索之前使用过的命令

    经常看见别人找之前敲的命令会用 history,其实已经有现成的快捷键可以用。

    按下 Ctrl + R 之后,输入查询的关键字,如果不符合,可以继续按 Ctrl + R 进行遍历。

    这个命令其实也是通过 history 记录来查询的。如果不喜欢这种方式,可以直接 history | grep xxx 也是不错的。

    转载请注明原文地址: https://ju.6miu.com/read-150369.html

    最新回复(0)