Sometimes, we need to repeat the previous command in Bash. Of course you can use the arrow keys to view commands you have run before. But here are some better ways, for example, master the following shortcut keys.
1) !!: Repeat the previous instruction
2) !a: Repeat the previous instruction headed by a
3) !number: Repeat the previous instruction with the number number recorded in the history table
4) !-number: Repeat the number instruction before execution
5) !$: indicates that you get the last item in the previous command
6) Use the Ctrl + r key combination to enter the historical search mode. In the history table, query a past command. After finding the command that needs to be executed repeatedly, press Enter to repeat the command parameters (that is, the 5th item in the previous point)
Ctrl+p Repeat the last command
Ctrl+a jumps to the first character
Ctrl+x is the same as above, but pressing it again will return to the original position from the new one
Ctrl+b moves one character forward without deleting characters
Ctrl+h deletes the previous character
Ctrl+u deletes all characters before the prompt
Ctrl+w same as above
Ctrl+d delete a character after the prompt or exit or logout
Ctrl+e Go to the end of the character
Ctrl+f moves one character back
Ctrl+k delete all characters after the prompt
Ctrl+k Cancel
ctrl+r searches forward for used commands
Ctrl+o Ctrl+y Ctrl+i Ctrl+m These 4 are not clear about how to use them
<TAB> command complete
CTRL-I is equivalent to pressing the tab key
CTRL-W does not delete all characters before the cursor, it deletes a word before the cursor
CTRL-P is the recall command to issue the previous command <===> CTRL-N is the recall command to issue the next command
ESC-F Cursor steps forward a word
ESC-B Cursor steps backwards a word
CTRL-M is equivalent to Enter key
CTRL-O is equivalent to Enter key
CTRL-V enables the next special character to be inserted at the current position, such as CTRL-V <TAB> can insert a <TAB> character at the current position, and its ASCII is 9. Otherwise, under normal circumstances, the result of pressing <TAB> is completed.
CTRL-C Undo the editing of the current command line and start another line.
CTRL-S Temporarily freezes the input of the current shell
CTRL-Q Thaw
ESC-c makes the first letter of the next word capitalize, and the cursor advances a word at the same time. If the cursor stays on a letter of the word, such as the o letter in word, the o letter becomes capitalized.
Instead of w
ESC-u makes all letters of the next word capitalize, and at the same time the cursor advances a word, the same as above, if the cursor is on the letter o, ord becomes capitalized and w remains unchanged.
ESC-l is the same as ESC-U, but it becomes all lowercase.
I tried all the ctrl key combinations of bash, and now summarized them as follows (all keys appearing below are ctrl key combinations):
1. U K Y
U deletes previous characters from the cursor (excluding)
K deletes the characters after the cursor (including)
Y glues out the characters you just deleted
2. D H
D Delete the characters at the cursor
H deletes a character before the cursor
3. A E
AMove the cursor to the beginning of the line
E Move the cursor to the end of the line
4. F B
F Move the cursor to the right by one character's position
B Move the cursor to the left by one character
5. N P
NNext command
P Previous command
6. L
L clear screen
7. R
R searches for commands entered before
8. T
T replaces the character at the cursor and the character before the cursor
Basic skills:
Use the up and down keys to see the history of the command
Modify contents on the left and right keypads
Tab fills the command name or directory and file name. If you are not the only one, press twice more, the list will be released.
!ls Repeat the last command starting with 'ls'. If ls -l and then ls -lcrt, then !ls is equivalent to ls -lcrt
ls
vi !$
The vi !$ in the second row is equivalent to vi , !$ is equal to the parameter of the previous command, and '$' is the last row, column, etc. according to the context.
ctrl key combination
ctrl+a: Move the cursor to the beginning of the line.
ctrl+b: Move the cursor one letter left by one
ctrl+c: Kill the current process.
ctrl+d: Exit the current shell.
ctrl+e:The cursor moves to the end of the line.
ctrl+h: Delete the previous character of the cursor, the same as the backspace key.
ctrl+k: Clear the contents from the cursor to the end of the line.
ctrl+l: Clear the screen, equivalent to clear.
ctrl+r: Search for commands you have typed before. There will be a prompt,Search based on the keywords you enteredbashofhistory
ctrl+u: Clears all contents from the front of the cursor to the beginning of the line.
ctrl+w: Remove a word before the cursor
ctrl+t: swap two characters before the cursor position
ctrl+y: Paste or restore the last delete
ctrl+d: Delete the letter where the cursor is located; pay attention to the difference between backspace and ctrl+h, these two characters before deleting the cursor
ctrl+f: Cursor right
ctrl+z: Transfer the current process to the background and restore it using the 'fg' command. For example, top -d1 and ctrl+z, go to the background, and then fg, restore again
Esc combination
esc+d: a word after deleting the cursor
esc+f: Jump a word to the right
esc+b: Jump to the left a word
esc+t: swap two words before the cursor position.