Article Title: Tips: how to operate Linux Command lines efficiently. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Bash has two input modes: vi Mode and emacs mode. emacs is the default mode and is faster than vi mode. Set-o vi and set-o emacs can be used for conversion.
1. Search in command history
We strongly recommend that you use Ctrl + r. This key combination is used to find the message history in reverse increments. Easy to use. For example, if you entered a command a long time ago, such. Gcc-c-DKKT-Dnnn and so on. It is difficult to use the up and down arrow keys. In this case, you can press Ctrl + r and enter gcc to quickly find the command, repeat Ctrl + r to find the earlier history.
In fact, Ctrl + s is a forward incremental search, but this shortcut is preset by the terminal to lock the screen, no effect. However, you can use the stty-ixon-ixoff command to unbind it. Another example is Ctrl + r and Ctrl + s.
For example, if I run the following command,
Echo aa bb cc d ee ff gg kk qq
Then I found that I want to modify d to dd. At this time, I only need to press Ctrl + r to enter d, then I will immediately locate d and press Ctrl + f, enter d.
2. Move in the command line
Ctrl + f Ctrl + B are the distances between the first and last characters
Alt + f Alt + B is the distance between the front and back of a word. This is very fast. For example, if you enter
$ Grep-e funtion file1 file2 file3
Then you find that the funtion is wrong. If you want to move it back and modify it, you can move it back after Alt + B. Soon.
Ctrl + a Ctrl + e move to the beginning and end of the row. This is also very useful. If you input a long string of command lines and find that the first word is spelled incorrectly, you can press Ctrl + a to the beginning and then modify it.
3. Delete
Alt + d delete a word to the right
Alt + Backspace delete a word from left
Ctrl + u Delete to left to first line
Ctrl + k Delete right to the end of the row
All these deletions are placed in the delete ring. You can use Ctrl + y to retrieve them. Alt + y moves in the delete ring, which means you can use cut and paste in the command line.
The above items can be improved a lot if you are skilled.
If you want to learn more about key binding, run the following command:
Bind-P
You can bind the following functions without the shortcut key. For example, I have bound two functions.
Bind-m emacs '"\ M-w": kill-region'
Bind-m emacs '"\ M-W": copy-region-as-kill'