Preface
Quick edit shell command line
The most common cause is that Nux beginners say that the most annoying thing is Linux/Unix command lines. If you are an impatient person, you can first try the comprehensive exercises at the end of the article to understand the shell shortcut keys. Maybe it will be more interesting to read the full text.
In fact, the command line is more efficient than the graphic interface. At least this is the case for me. As soon as I see the so-called ides, I feel dazzled. the area of Code actually used is squeezed to be as big as a pack of cigarettes. Sometimes it takes a long time to find a dialog box for an option.
Why are so many people afraid of command line?
I think the biggest problem is that many people think that command line input and editing are very slow and inefficient. However, for Linux/Unix systems that obtain the overall architecture from the kernel, and even the smallest small application software, which is supported by text, no skillful command line skills are really difficult to understand. I hope this article will help you improve the efficiency of using the command line.
However, since there are too many Linux/Unix releases and several mainstream shell versions, the content mentioned in this article may differ from your system, but the idea is the same, find out how to edit command lines on your platform.
In addition, many shell shortcuts are the same as those of vim and Emacs. Therefore, skillful use of shell shortcuts can be helpful for adapting to other software under * nux.
In addition to the skills mentioned in this article, you can collect and understand the command line skills. Of course, if you often need to enter complicated commands, you are advised to write shell scripts, define functions, alias, and other techniques for implementation.
My current System Configuration
Kernel: 2.6
Shell version: Gun bash
Window System: GNOME
Terminal: gnome-Terminal
Start now.
I. Automatic completion: [Tab]
This technique should be used by many people, that is, when entering commands, directories, or file names, press the [Tab] key. The system will help you complete the items that may be entered. If there are multiple selection systems, they will be listed. You can enter one or more Charactors and then press [Tab].
Lab:
$ ec
Press [Tab] and complete the following:
$ echo
2. Search for and execute History commands: [Ctrl + R], [Ctrl + P], [Ctrl + N]
Press the [R] key at the same time as the [CTRL] key on the terminal, and the prompt is displayed: (reverse-I-search ),
In this case, enter the commands you have previously entered. Each time you enter a character, the terminal will scroll to display your historical commands. When you find the appropriate historical commands
[Enter], and the history command is executed.
In addition,[Ctrl + P]
Or[Ctrl + N]
You can quickly scroll forward or backward to find a history command, which is useful for quickly extracting commands that have just been executed.
Lab:
$ echo "hello, world" [Enter]
$ hello, world
[Ctrl + R] (then input echo)
(reverse-i-search)`ch': echo "hello,world" [Enter]
$hello,world
3. Cancel the command input: [Ctrl + C]
This shortcut can help you safely exit from a command that may be boring to you !! Maybe it's not worth mentioning, but experience tells me it's useful. Many Unix beginners will habitually press [enter] to get rid of the predicament, but there may be catastrophic events, such as deleting an important configuration file :(
Iv. Shortcut Keys for cursor jump:
To make it easier for everyone to remember, add some help Words in English to the back
[Ctrl + A] Jump to ahead of line at the beginning of the command line
[Ctrl + E] jump to the end of the command line end of line[Ctrl + F] Jump one character forward to jump forward one character
[Ctrl + B] Jump back to a character jump backward one character
[Alt + F] Jump forward to the first character of the next word
[Alt + B] Jump backward to the first character of the next word
5. Shortcut Keys for editing commands:
[Ctrl + W] It is useful to delete a word forward to deal with the entered incorrect word (the front is on the left)
[Alt + D] delete a word backward (after the right side)
[Ctrl + u] Delete All characters from the current position of the cursor to the beginning of the line (in fact, it is placed in the buffer, you can use Ctrl + Y to restore back:
Thank you for choosing kevinbin.
)
[Ctrl + k] Delete All characters from the current position of the cursor to the end of the line (same as above)
[Ctrl + D] Delete the character at the current position of the cursor and press it until the end of the line.
[Ctrl + Y] paste the last deleted word
6. Quick Screen Cleaning;
CTRL + L
VII. Configuration prompt;
If you use gnome-teminal in the terminal window of gnome, the GNU shell shortcut on the top will conflict with the window Shortcut of gnome.
Then you need to make the following Configuration:
Select "edit"-] "keyboard shortcuts..." in the menu bar of gnome-terminal to open the "keyboard shortcuts" dialog box, and check the following two Option
"Disable all menu access keys (such as Alt+f to open File menu)"
"Disable menu shortcut key (F10 by default)"
As for how to configure the KDE terminal window in Kde, please familiarize yourself with KDE. I haven't installed KDE for a long time.
8. Comprehensive Exercises;
The shortcut keys listed above, exercise 2 ~ We should be proficient in three days. To help you quickly understand and remember, let's do a small comprehensive exercise:
Step 1: Echo
$ echo "hello, world." [Enter]
Input the echo "Hello, world" command and press enter to view the terminal output:
$ hello, world.
Step 2: [Ctrl + R]
Let's try to find out the history command echo "Hello, world. "At this time, we press the three keys [e], [c], and [H]. This historical command has probably been found,
The display of the terminal should be as follows:
(reverse-i-search)`ech': echo "hello,world."
Now, if [enter] is used, this command will be executed again, but now let's edit the command line.
Step 3: [Ctrl + A]
In this way, the history command echo "Hello, world." is taken out and the cursor is positioned at the beginning of the line. At this time, the cursor should be highlighted on the E character of the ECHO command.
The display of the terminal should be as follows:
$ echo "hello,world"
Step 4: [Alt + D]
The echo command is deleted, and the cursor is still at the beginning of the line. The terminal is displayed as follows:
$ "hello, world."
Step 5: Enter the command "printf"
Let's try to use the POSIX system to call printf to replace the shell command echo. Input [p] [r] [I] [N] [T] [f], and the terminal displays:
$ printf "hello, world."
The cursor is highlighted after the f character.
Step 6: [Ctrl + E]
The cursor jumps to the end of the command line.
Step 7: [Ctrl + B]
Move the cursor back to a character. The cursor should be highlighted in double quotation marks.
Step 8: Enter the newline Escape Character "/N"
Enter [/] [N]. The terminal display at this time should be:
$ printf "hello, world./n"
You can run the [enter] command.
9. About this article;
When you are skilled, the above steps should be completed in 20 seconds. I hope everyone can become a master of command line !!!
10. related documents;
Introduction to Linux Shell
Linux Command and executable program path settings
From: http://www.linuxsir.org/main/node/151