Bash shortcut Keys Daquan

Source: Internet
Author: User
Tags control characters

Some instructions for shortcut keys:

    1. Ctrl=c: This key refers to the CTRL key on the PC keyboard
    2. Alt=m: This key is the ALT key on the PC keyboard, if you do not have this key on the keyboard, you can try to use the ESC key instead
    3. Shift=s: This key is the SHIFT key on the PC
    4. Esc=e: This key is the ESC key on the PC keyboard, this key is usually in the upper left corner of the keyboard
    5. Backspace=del: This key is the BACKSPACE key on the PC keyboard, usually located in the upper right corner of the main keyboard area
    6. In the text "[]" surrounded by the content of the shortcut key, "-" on both sides of the content is to hold down the left button, and then press the right button to obtain, "," the contents of the comma on both sides of the first press the left button, release and then press the right button. such as: [Ctrl-v] is to indicate that the CTRL key is pressed, do not release, and then press the V key.
    7. By default, the form of shortcut keys is: <ctrl | ALT | ESC >-[SHIFT-]<char>. That is, one of the CTRL, ALT, ESC starts with an underscore, a Shift, an underscore, and a character. Where the shift and "-" in brackets are sometimes omitted.
    8. By default, the shortcut key is only the last character, and the other key values are function keys
    9. appears [Ctrl-?] This type of shortcut is due to "?" is a character that needs to be obtained by using the SHIFT key, so this type of shortcut is used by default [ctrl-shift-?]

Note that in bash, shortcut keys may be written in octal or hexadecimal form (following the escape character); The shortcut keys in the script file do not always work. In addition, shortcut keys have a rule,Ctrl starts with the shortcut keys are generally for the character, and alt the beginning of the shortcut key is generally for the word .

Bash, if you are using a Shell script file, shortcut keys are not necessarily the same, sometimes the same shortcut will appear different performance, this situation is usually caused by the different mode of bash, you can use the SET command to adjust the mode:

123456 set-o emacs##切到emacs模式set -o vi##切到vi模式set-o## 查看当前选项的设置状态

This is the option for bash, you can set it according to the situation, this article uses the Emacs mode.

shortcut Keys Shortcut key Description
CTRL-A Move the cursor to the beginning of the line (under command)
CTRL-B BACKSPACE (non-destructive), this just moves the cursor position back one position.
CTRL-C Interrupt to end a foreground job.
CTRL-D "EOF" (End of File: End of files). It is used to represent the end of standard input (stdin). When you enter text in the console or Xterm window, CTRL - D Delete the character under the cursor.

Exit from a shell (similar to exit). If no characters exist, CTRL -the D session is logged out. In a xterm window, the effect of closing this window is generated.

CTRL-E Move the cursor to the end of the line (at the command line)
CTRL-F Move the cursor forward one character (below the command line)
CTRL-G BEL. On some older printer terminals, this raises a bell. May be a beep on the xterm terminal.
CTRL-H Erase (Rubout) (destructive backspace). While the cursor is moving back, erase one character before the cursor.
CTRL-I Horizontal tab.
CTRL-J New lines (line feed) and start at the beginning. In the script, it may also be represented as an octal form (' 12′ ') or hexadecimal (' \x0a ').
CTRL-K Vertical tab (Vertical tab). When you enter text in the console or Xterm window,CTRL-KAll characters from the cursor to the end of the line are deleted.

In the script, it may also be represented as an octal form (' 13′ ') or hexadecimal (' \x0b '). In the script, CTRL - K There may be a different behavior, and the following example gives a different behavior:

123456789 #!/bin/bash ## a ctrl-k vertical tab var =$ ' \x0abottom line\x0btop line\x0a ' ## Direct output Code class= "Actionscript3 plain" >echo ## use Col to filter control characters echo " $var " | Col ## the above display will be different exit 0
CTRL-L Skip the paper, change the page (formfeed), clear the screen.

Clear the terminal screen. On the terminal, this command acts like a clear command. But when this command is sent to the printer, Ctrl-l jumps directly to the end of the paper (Paper sheet).

CTRL-M Enter (carriage return).
CTRL-N Erases a line of text recalled from the history buffer (at the command line). If the current input is selected in the history, this is the beginning of this history, each press, is a closer command.
CTRL-O Produces a new line (at the command line).
CTRL-P Recall the last command (at the command line) from the history buffer. The order of this shortcut is recalled by from near, that is, by pressing once, recalling the previous command, and then pressing again, recalling the previous command, which is CTRL N starting with the current input, but the two commands operate just the opposite, CTRL - N is starting from the beginning by far and near (if the beginning is a historical order).
CTRL-Q Resume (XON). Restore/Thaw, this command is used to restore the terminal's stdin, see CTRL - S .
CTRL-R Backtracking search (backwards search) The text within the history buffer (at the command line). Note: After pressing, the prompt becomes (reverse-i-search)‘‘: the input search content in single quotation marks, and the most recent matching history command appears after the colon.
CTRL-S Suspend (XOFF), hangs. This is the stdin that freezes the terminal. To recover can press CTRL - Q .
CTRL-T Swaps the character contents of the cursor position with the previous position of the cursor (at the command line). For example echo $var; , assuming that the cursor is on a, then, after pressing C-T, V and a will swap positions: echo $avr; .
CTRL-U Erases all character content from the cursor position to the beginning of the line. Under certain settings-the CTRL U input of the entire row is not deleted with the cursor position as a reference.
CTRL-V When you enter text, you can insert a control character after you press C-V. For example: As echo -e ‘\x0a‘; with echo <CTRL-V><CTRL-J>; these two effects. This feature works well in a text editor.
CTRL-W When typing text in the console or in a xterm window, CTRL -the W contents are removed from the first white-space character that is backward (back) at the cursor. In some settings, CTRL - W Delete the cursor (back) to the first character that is not between a literal and a number.
CTRL-X In some word-processing programs, this control character will cut the highlighted text and copy it to the Clipboard.
CTRL-Y Paste the previously cleared text back (mainly for CTRL - U or CTRL - W ).
CTRL-Z Pauses a foreground job, and also acts as a replacement in some text handlers, and as EOF (End-of-file) characters in the Msdos file system.
CTRL-\ Exit. and CTRL - C almost, you may dump a "core" file into your working directory (this file may not work for you).
CTRL-/ Undo action, Undo.
CTRL-_ Undo the action.
CTRL-xx Toggles between the beginning of the line and the cursor two positions, where there are two "x" characters.
ALT-B The cursor jumps back one word, and the word is bounded by non-letters (jumping to the beginning of the word where the cursor is currently located).
ALT-F The cursor jumps forward one word (moves to the end of the word where the cursor is located).
ALT-D Deletes everything at the cursor position to the end of the word at the cursor (if the cursor is at the beginning of the word, the entire word is deleted).
ALT-BASKSPACE Deletes all content at the beginning of the word at the cursor location.
ALT-C Capitalize the letter at the position of the cursor (if the cursor is in or before the beginning of the word).
ALT-U Capitalizes all letters in the position of the cursor to the ending.
ALT-L Converts all letters of the cursor position to the ending to lowercase.
ALT-R Cancels all changes and restores the current row to its original state in the history (provided the current command is from the history, and if it is entered manually, the row is emptied).
ALT-T When words are present on both sides of the cursor, swap the positions of the words on both sides of the cursor. such as: abc <ALT-T>bcdbcd abc
ALT-. Use the last word of the previous command (the command itself is also a word, see the word indicator concept in the Bang command in the following article).
ALT-_ With ALT - . .
ALT-数值 This value can be either positive or negative, the key alone has no effect, must be followed by the other content, if it is followed by a character, it indicates the number of repetitions. such as: [ ALT - 10 , k ] The cursor position will be inserted 10 k characters (negative value in this case is not valid); If you follow the command, the number will affect the execution of the following command, such as: [ ALT - - 1 0 , CTRL-D] CTRL D performs 10 operations in the direction of the opposite (negative) direction of the default.
ALT-< Moves to the first line of the history Record command.
ALT-> Moves to the last line of history, which is the row that is currently being entered (empty if no input is entered).
ALT-P Search forward from the current line, and it is necessary to move to up, and use non-incremental search to find the user-supplied string when moving.
ALT-N Searches backward from the current line and, if necessary, moves to "down", using a non-incremental search to find the user-supplied string.
ALT-CTRL-Y Inserts the first parameter of the previous command (usually the second word in the previous line) on the flag point. If there is a parameter n, insert the nth Word of the previous command (the word number from the previous line starts with 0, see history extension). A negative argument inserts the nth word that starts at the end of the previous command. The parameter n is passed by m-no, such as: [ ALT - 0 , ALT - CTRL - Y ] inserting the No. 0 word (the command itself) of the previous command.
ALT-Y Polls to the delete ring and copies the new top text. This command can only be CTRL Y used after yank[-] or yank-pop[ M - Y ].
ALT-? Lists the entries that can be complete before the Mark Point.
ALT-* ALT ? Insert all text entries that can be generated by the full [-] command before inserting them into the flag point.
ALT-/ An attempt was made to complete the file name of the text before the flag point. [ CTRL - X , / ] The text before the mark point as the file name and list the items that can be complete.
ALT-~ Use the text in front of the logo as the user name and try to complete the completion. [ CTRL - X , ~ ] lists the entries that can be used as the user name complement flag point.
ALT-$ Think of the text before the mark point as a shell variable and try to complete the completion. [ CTRL - X , $ ] lists the entries that can be used as the variable complement flag point.
ALT-@ The text before the mark Point is treated as a hostname and attempted to complete. [ CTRL - X , @ ] lists the entries that can be used as the host complement flag point.
ALT-! The text before the mark Point is treated as a command name and attempted to complete. The command name completion is followed by the alias, reserved word, shell function, shell internal command, and finally the executable file name. [ CTRL - X , ! ] The text before the mark Point as the command name and the completion of the article can be complete.
ALT-TAB Compare the text in front of the mark point to the text in the history to find a match and try to complete the completion.
ALT-{ Complete the file name, and put the list of entries that can be complete between the braces so that the shell can use it.

Under Bash, if you can use the shortcut keys properly, the operation on the Linux system becomes very fast, for example, when we create a file using cat, we can use the shortcut key [ctrl-d]:

12345678910 ## 不用快捷键cat >>/tmp/test<<_EOF##这里是内容##最后我们要在新行里面输入_EOF##cat见到_EOF才会将内容写到文件中##使用快捷键cat >>/tmp/test##这里输入内容##输入完毕之后,直接[CTRL-D]结束

Sometimes we need to create a file and then manipulate the file:

12345678 touch /tmp/a-test-file-from-blog.useasp.net## 不使用快捷键,文件名要重新输入chmod u+x /tmp/a-test-file-from-blog.useasp.net##使用快捷键chmod u+x <ALT-.>## 快捷键[M-.]自动会将上面的最后一个参数附加

What, is there more efficiency?

Of course, bash shortcut keys only in the continuous use, to achieve real efficiency, in the beginning even to use that shortcut to think about a half-day situation, high efficiency is very difficult-but the knife does not mistakenly cut timber workers, the upfront investment is worthwhile.

If you want your bash to have a few different, you can also customize the shortcut keys, using the bind command, bash in the shortcut is actually readline to provide, so, here the shortcut key is configured in the Readline,readline of the two shortcut keys, One is the function shortcut inside the ReadLine, and the other is the execution of the shell command, setting the time slightly different:

1234567891011121314 ## View function names that can be used in ReadLine bind-l ## View the currently bound case configuration with its corresponding function bind-v ## Shortcut keys already bound bind-p  ## Bind custom Execute Command shell command shortcut key bind-x "\c-x\c-l": Ls-al ' ## after binding, press [C-x,c-l] to execute ls-al  ## bound built-in functions bind "\c-x" :backword-delte-char # #这个是这行Readline库中的函数backword-delte-char

This setting is only valid for the current session, and once the session is lost, the shortcut keys for the setting are lost, so we need to write the shortcut key's configuration to the file in order for the shortcut key to be permanently valid. In the Linux system, can permanently save the shortcut key place has two, the global and the user's configuration file, the global is/ETC/INPUTRC, but the user is in the user's root directory ~/.inputrc, the global affects all users, but the user root directory will only have the influence to the corresponding user. The inputrc file might look like this:

12345678910111213141516171819202122232425262728293031 ## 本例来自CentOS6.4的默认配置文件$if mode=emacs# for linux console and RH/Debian xterm"\e[1~": beginning-of-line"\e[4~": end-of-line# commented out keymappings for pgup/pgdown to reach begin/end of history#"\e[5~": beginning-of-history#"\e[6~": end-of-history"\e[5~": history-search-backward"\e[6~": history-search-forward"\e[3~": delete-char"\e[2~": quoted-insert"\e[5C": forward-word"\e[5D": backward-word"\e[1;5C": forward-word"\e[1;5D": backward-word# for rxvt"\e[8~": end-of-line"\eOc": forward-word"\eOd": backward-word# for non RH/Debian xterm, can‘t hurt for RH/DEbian xterm"\eOH": beginning-of-line"\eOF": end-of-line# for freebsd console"\e[H": beginning-of-line"\e[F": end-of-line$endif

Description

1. In the configuration file, \c represents ctrl,\m on behalf of the ALT,\E representative esc,\\ is a backslash \,\ ' is a single quote, \ ' is a double quotation mark;

123456 \C- control prefix\M- meta prefix\e an escapecharacter\\ backslash\" literal ", a double quote\’ literal ’, a single quote

2. If you want to see the character sequence of a function key can be achieved by [ctrl-v], or enter cat back, enter the editor, press the shortcut key directly
3. Characters may be represented in the configuration file using octal or hexadecimal notation.

If we set up the appropriate shortcut for the commonly used operation, perhaps the previous need to Balabala knock half command, you can do a shortcut key, which will undoubtedly greatly improve our efficiency! Shortcut Key Bar, Sao year!

Bash shortcut Keys Daquan

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.