Shortcut keys and tips commonly used in shell terminal

Time:2021-12-2

Common shortcut keys and tips for terminal


C stands for Ctrl (command). Some commands need to be executed after entering. In the direction, the front is left and the rear is right.

  • Use Wildcards

  • useTab complete

  • Clear or C ^ l clear screen

  • C ^ D close(When there is no input on the current command lineThe terminal will be closed. If there are multiple tabs, only the current tab will be closed.)

Historical command

  • C ^ R search history command

  • View history commands

    • cat ~/.bash_history

    • History parameter: – C clear history command | – W write history command in cache to ~ /. Bash_ History file

  • /You can set the number of historical commands saved in the / etc / profile (10000 by default)

Command reuse

  • The up arrow or C ^ P switches to the previous command

  • Down arrow or C ^ n switch to the next command

  • Page up and page down are the first command and the last (latest) command respectively

  • !! (two exclamation marks) repeat the last command (can be used after sudo / Su to repeat it with sudo / SU)

    • !$ The dollar sign is replaced with the last word of the previous command

    • !^ The upper angle brackets are replaced with the first word of the previous command

    • ! N execute the nth command in history

    • ! String executes a command that begins with that string

Program status

  • C ^ C terminate (or end the line currently being entered)

  • C ^ s suspended (paused)

  • C ^ Z suspend and put in background

  • FG or BG put the background program into the foreground for execution

Several methods of executing programs in the background

  • Command + & e.gping z.cn -c 10 &

  • (Command + &) e.g(ping z.cn -c 10 &)

  • Nohup + Command + & e.gnohup pacman -Syu --noconfirm &

  • Setid + command, such assetid ping z.cn -c 10

  • Screen or TMUX

delete

  • Delete before C ^ H (same as backspace key)

  • Delete after C ^ D (same as delete)

  • C ^ w delete the word before the cursor

  • Alt-uDelete the word after the cursor

  • C ^ u delete everything in front of the cursor

  • C ^ k delete everything after the cursor

Replace (case conversion and position swap)

The word is the word where the cursor is sitting

  • Alt-u willIn this wordThe letters at and after the cursor are capitalized

  • Alt-l willIn this wordThe position of the cursor and the letters after it become lowercase

  • Alt-C willIn this wordThe cursor position changes to lowercase, and the subsequent letters change to lowercase

be careful: the terminal may be able to select the cursor style. For example, the square cursor will cover the whole character, the underline cursor will be marked below the whole character, and the vertical cursor will appear between the two characters. The following is the description of the vertical cursor. The box cursor and underline cursor take the left edge of the cursor as the reference position before and after determination.

  • C ^ t 1. When the cursor is between characters,Swap the position of the two characters before and after the cursor/2. When the cursor is at the end of all characters, swap the position of the first two characters of the cursor

    **Note * *: in the box and underline cursor, 1 in this sentence should be described as:
    
    When the cursor is on a character, swap the position of the character where the cursor is and the character before the cursor
    
    Note: spaces / tab are also characters.
    ​
  • Alt-t transposes words, refer to C ^ t

  • Shift + Ctrl + C copy

  • Shift + Ctrl + V paste

Move Cursor

  • C ^ a move to start (same as home key)

  • C ^ e move to end (same as end)

  • Move C ^ f forward once (the same as the left arrow key)

  • C ^ B move back once (same as right arrow key)

  • Move one word before Alt-F

  • Move one word after alt-b

  • ESC ^ f moves to the end of the current word

  • ESC ^ B moves to the beginning of the current word

  • Ctrl-x-x toggles between the last two cursor occurrences