zoukankan      html  css  js  c++  java
  • Linux

    Linux 命令行快捷键

    在操作Linux的时候,有的时候从其他地方copy一段命令,发现前面多了东西或少了东西,要移动左右键到最前面,改完再移动到最后面,真是麻烦至极,幸好有快捷键,来解决一些这样的问题。

    涉及在linux命令行下进行快速移动光标、命令编辑、编辑后执行历史命令、Bang(!)命令、控制命令等。让basher更有效率。

    常用

    Ctrl + 左右键:在单词之间跳转

    Ctrl + A:跳到本行的行首

    Ctrl + E:跳到页尾

    Ctrl + U:删除当前光标前面的所有文字(还有剪切功能)

    Ctrl + K:删除当前光标后面的所有文字(还有剪切功能)

    Ctrl + L:进行清屏操作

    Ctrl + Y:粘贴Ctrl + U或Ctrl + K剪切的内容

    Ctrl + W和Alt + D:对于当前的单词进行删除操作,W删除光标前面的单词的字符,D则删除后面的字符 

    Alt + Backsapce:删除当前光标后面的单词

    说明

    Ctrl + K: 先按住 Ctrl 键,然后再按 K 键;

    Alt + K: 先按住 Alt 键,然后再按 K 键;

    Esc + K:先单击 Esc 键,然后再按 K 键。

    移动光标

    Ctrl + A:移到行首

    Ctrl + E:移到行尾

    Ctrl + B:往回(左)移动一个字符(相当于左键)

    Ctrl + F:往后(右)移动一个字符(相当于右键)

    Ctrl + XX:(两个X)在命令行尾和光标之间移动

    Alt + B:往回(左)移动一个单词

    Alt + F:往后(右)移动一个单词

    Esc + B:往回(左)移动一个单词

    Esc + F:往后(右)移动一个单词

    Esc + T:交换光标位置前的两个单词

    编辑命令

    Ctrl + H :删除光标左方位置的字符

    Ctrl + D:删除光标右方位置的字符(注意:当前命令行没有任何字符时,会注销系统或结束终端)

    Ctrl + W :由光标位置开始,往左删除单词。往行首删

    Alt + D :由光标位置开始,往右删除单词。往行尾删

    Esc + D :由光标位置开始,删除单词,直到该单词结束。

    Ctrl + K :由光标所在位置开始,删除右方所有的字符,直到该行结束。

    Ctrl + U :由光标所在位置开始,删除左方所有的字符,直到该行开始。

    Ctrl + Y :粘贴之前删除的内容到光标后。

    Ctrl + T :交换光标处和之前两个字符的位置。

    Alt + . :使用上一条命令的最后一个参数。

    Ctrl + -:回复之前的状态。撤销操作。

    Ctrl + A + K ,或 Ctrl + E + U 或 Ctrl + K + U 组合可删除整行。

    查找历史命令

    Ctrl + P:显示当前命令的上一条历史命令(相当于上键)

    Ctrl + N:显示当前命令的下一条历史命令(相当于下键)

    Ctrl + R:搜索历史命令,随着输入会显示历史命令中的一条匹配命令,Enter键执行匹配命令;ESC键在命令行显示而不执行匹配命令。

    Ctrl + G:从历史搜索模式(Ctrl + R)退出。

    控制命令

    Ctrl + L:清除屏幕,然后,在最上面重新显示目前光标所在的这一行的内容。

    Ctrl + O:执行当前命令,并选择上一条命令。

    Ctrl + S:阻止屏幕输出

    Ctrl + Q:允许屏幕输出

    Ctrl + C:终止命令

    Ctrl + Z:挂起命令(使用‘fg’命令恢复)

    重复执行操作动作

    Esc – 操作次数 操作动作 : 指定操作次数,重复执行指定的操作。

    Bang(!)命令

    !! :执行上一条命令。

    ^foo^bar :把上一条命令里的foo替换为bar,并执行。

    !wget :执行最近的以wget开头的命令。

    !wget:p :仅打印最近的以wget开头的命令,不执行。

    !$ :上一条命令的最后一个参数, 与 Alt - . 和 $_ 相同。

    !* :上一条命令的所有参数

    !*:p :打印上一条命令是所有参数,也即 !*的内容。

    ^abc :删除上一条命令中的abc。

    ^foo^bar :将上一条命令中的 foo 替换为 bar

    ^foo^bar^ :将上一条命令中的 foo 替换为 bar

    !-n :执行前n条命令,执行上一条命令: !-1, 执行前5条命令的格式是: !-5

    The default Linux Bash shell might, at first, feel like a rather restrictive environment to work in. Many users get stuck on the inability to select text with the mouse, or having to rely heavily on the arrow keys to fix a small issue toward the end of a long command.

    The truth is that Bash is actually quite user-friendly—once you know how to control all of its nuances. So, if you're going to spend any meaningful amount of time on your VPS, maintaining it or installing new services via the command line, you'll benefit from learning these Bash shortcuts.

    First off, let's just throw all the shortcuts at you, and then follow that up with some more detail on a select few, plus video!

     
    ShortcutAction
    Navigation  
    Ctrl + a Go to the beginning of the line.
    Ctrl + e Go to the end of the line.
    Alt + f Move the cursor forward one word.
    Alt + b Move the cursor back one word.
    Ctrl + f Move the cursor forward one character.
    Ctrl + b Move the cursor back one character.
    Ctrl + xx Toggle between the current cursor position and the beginning of the line.
    Editing  
    Ctrl + _ Undo! (And, yes, that's an underscore, so you'll probably need to use Shift as well.)
    Ctrl + xCtrl + e Edit the current command in your $EDITOR.
    Alt + d Delete the word after the cursor.
    Alt + Delete Delete the word before the cursor.
    Ctrl + d Delete the character beneath the cursor.
    Ctrl + h Delete the character before the cursor (like backspace).
    Ctrl + k Cut the line after the cursor to the clipboard.
    Ctrl + u Cut the line before the cursor to the clipboard.
    Ctrl + d Cut the word after the cursor to the clipboard.
    Ctrl + w Cut the word before the cursor to the clipboard.
    Ctrl + y Paste the last item to be cut.
    Processes  
    Ctrl + l Clear the entire screen (like the clear command).
    Ctrl + z Place the currently running process into a suspended background process (and then use fg to restore it).
    Ctrl + c Kill the currently running process by sending the SIGINT signal.
    Ctrl + d Exit the current shell.
    Enter~. Exit a stalled SSH session.
    History  
    Ctrl + r Bring up the history search.
    Ctrl + g Exit the history search.
    Ctrl + p See the previous command in the history.
    Ctrl + n See the next command in the history.

    All of these keyboard shortcuts are enabled by Emacs mode in Bash. If you'd like to use Vi shortcuts instead, you can enable that mode and use different shortcuts instead. In addition, most of these are compatible with Zsh as well, although you might find that a few don't work or require slightly altered shortcuts.

    As promised, let's take a slightly longer dive into some of the more complex shortcuts, particularly the ones that could benefit from some visual reinforcement as to their function.

    Ctrl + x + x

    Technically, this command is activated by hitting Ctrl + x twice, but it also works to just hold down Ctrl and hit x twice.

    This command is particularly useful if you want to quickly hop to the beginning of a lengthy command to fix something at the beginning, and then hop to the end.

    Ctrl + _

    The magical undo keystroke! If you accidentally delete a character or even a whole word via some of the shortcuts listed above, not all is lost. This even works after deleting a whole line with Ctrl + u, but doesn't work after you've executed the command.

    Ctrl + l

    Clearing the terminal is less about productivity, perhaps, and more about aesthetics, or starting from a clean slate. Whatever your reason, this simple command will help you keep track of your prompt and put the past behind you.

    Ctrl + c

    The SIGINT shortcut is, truly, one of the most used shortcuts out there. It will attempt to interrupt the currently running process, and is used frequently to stop commands entered with a typo, or those that appear to have hung up.

    The next steps

    We hope this is a useful resource as you work to become more proficient in navigating the Linux terminal with ease. Learning all of these shortcuts—or even a select few of them—will take some time, but your efforts won't go unrewarded.

    If you have a favorite Bash shortcut that you'd like to share, we would love to hear it! Let us know the details in the comments and we'll add it to the list. We hope this will become an ever-growing and ever-improving resource, so we're always looking for more contributions.

    参考:

    https://blog.csdn.net/mxw2552261/article/details/85271813

    https://blog.ssdnodes.com/blog/cheatsheet-bash-shortcuts/

  • 相关阅读:
    [转]vc中socket编程步骤
    [转载]使用命名管道实现进程间通信
    换肤软件摘要
    3D 专业词汇 (转)
    如何从 Microsoft DirectShow 筛选器图形获取数据(转)
    “人大艺术学院”“赵雅芝中文网”等网站被挂马 狼人:
    微软将发布5月安全漏洞补丁 修补PPT 狼人:
    专家提醒:网络挂马借“海运女”传播 狼人:
    黑客借“甲型流感”传毒 挂马疾病预防控制中心网站 狼人:
    黑客称攻破乔布斯亚马逊网站账户 欲售相关信息 狼人:
  • 原文地址:https://www.cnblogs.com/firestar277/p/14672268.html
Copyright © 2011-2022 走看看