Linux Basics
1 Linux Commands
If there is no difference between using Gui,linux and Windows. One feature of the Linux learning application is the use of the command line. After logging in to Linux, we can enter the command after the # or $ character, sometimes with the option or parameter (arguments) followed by the command. That is, command [options] [arguments]//brackets are optional, that is, some commands do not require options and do not require parameters
Options are switches that adjust the execution behavior of a command, and different options determine the result of the command being displayed differently.
A parameter is an object that the command acts on. such as LS command, ls or LS. Display is the contents of the current directory, here "." Is the parameter that represents the current directory, which is the default that can be omitted. We can use Ls-a. Displays all content in the current directory, including hidden files and directories. Where "-a" is the option, which changes the display content.
2 Man command
Whether learning programming or Linux commands, mastering the use of help documents is very important, is the important way of extrapolate. Man is the abbreviation of Manul, and we can see the man's help through the man Mans. Man has a-K option to use very well, this option lets you learn commands, programming when you have a search engine, you can extrapolate. We illustrate through an example, such as the data structure in the middle of the sorting (sort), I do not know the C language has not done this function, can be "man-k sort" to search, because is to find C library function, we focus on Band 3, Qsort seems to be a good option. Combined with the grep command and pipeline that you learned later, you can find multiple keywords: man-k key1 | grep Key2 | grep Key3 | ...
3 Cheat Command
Cheat is cheating, small copy of the meaning. The Cheat command is an interactive cheat sheet application that is distributed to Linux command line users under the GNU General Public License. It provides a display of Linux command use cases, including all of the options and short but understandable features of the command. It is possible to cheat with the cheat command. :)
4 Other Core commands
and find the relevant core commands are also Find,locate,grep,whereis,which, where:
- Find where a file is located in the system, locate is a quick version of Find (Windows has a everything tool similar to locate).
- grep can retrieve full-text files, support regular expressions, and regular expressions are also an important meta-knowledge.
- Whereis,which tells you where the command tool is installed.
The above command includes man-k has a common feature is based on "search", learn to extrapolate, we focus on learning, mastered them, other commands can be self-taught. You try "man find", "cheat find".
The foundation of C language programming in experiment two Linux
First, the purpose of the experiment
1. Familiar with the development environment under the Linux system
2. Familiar with the basic operation of VI
3. Familiar with the basic principles of the GCC compiler
4. Familiar options for using the GCC compiler
5. Be familiar with GDB debugging technology
6. Familiarity with makefile fundamentals and grammatical norms
7. Mastering the generation of static and dynamic libraries
Second, the experimental steps
1. Shortcut keys
In Ubuntu:
2. Vim
Vim is a very good text editor.
3. GCC
GNU CC (referred to as GCC) is an ANSI C-compliant compilation system in the GNU project that compiles programs written in languages such as C, C + +, and object C. GCC is also a cross-platform compiler that can develop software on the current CPU platform for a variety of hardware platforms of different architectures, so it is especially suitable for development in the embedded domain.
4. gdb
Recommended to use CGDB, better than GDB, familiar with the VC debugging methods, you can use DDD. Note Use GCC to compile with the "-G" parameter. Refer to the GDB Reference Card GDB's most basic commands are:
- GdB Programm (Start gdb)
- B Set Breakpoints (4 breakpoints are set: Line breakpoint, function breakpoint, conditional breakpoint, temporary breakpoint)
- Run starts running the program
- BT Print function Call stack
- P View variable values
- C continue running from the current breakpoint to the next breakpoint
- N Single Step operation
- S Single Step operation
- Quit Quit GDB
I. Introduction of VIM Mode
1, from the VI-born vim has a variety of models, this unique design easy to confuse the beginner. Almost all editors have two modes of inserting and executing commands, and most editors use a different approach to vim: the command directory (mouse or keyboard driver), the combination of keys (usually with the control key (CTRL) and the ALT key (ALT)) or the mouse input. Vim and VI, just as the keyboard to switch among these modes. This allows vim to operate without a menu or mouse, and to minimize the operation of key combinations. It can greatly enhance the speed and efficiency of the text entry clerk or programmer.
VIM has 6 basic modes and 5 derivation modes, and here we simply introduce the next 6 basic modes:
In normal mode, the editor commands, such as moving the cursor, deleting text, and so on. This is also the default mode after Vim is started. This is exactly the opposite of what many new users expect (most editor default mode is insert mode).
Vim's powerful editor can come from its normal mode commands. Normal mode commands often require an operator end. For example, the normal mode command DD deletes the current line, but the first "D" can be followed by a different move command instead of the second d, such as the "J" Key moved to the next line to delete the current row and the next row. You can also specify the number of commands to repeat, 2DD (repeat DD two times), and the DJ's effect is the same. Users learn a variety of text between the move/jump commands and other common mode of editing commands, and can be used flexibly combined, can be more efficient than those without the pattern of the editor for text editing.
In normal mode, there are many ways to get into insert mode. The more common way is to press a (append/append) key or I (insert/insert) key.
- Insertion modes (insert mode)
In this mode, most keystrokes insert text into the text buffer. Most new users want this mode to persist throughout the text editor editing process.
In insert mode, you can press the ESC key back to normal mode.
- Visual modes (visual mode)
This pattern is similar to normal mode. However, the move command expands the highlighted text area. The highlighted area can be a character, a line, or a piece of text. When a non-moving command is executed, the command is executed to the highlighted area. Vim's "text object" can also be used in this mode as the move command.
- Selection mode (select modes)
This pattern is similar to the behavior of the modeless editor (the way Windows standard text controls are). In this mode, you can use the mouse or cursor keys to highlight the selection of text, but the input of any character, Vim will use this character to replace the selected highlighted text block, and automatically enter the insertion mode.
In command-line mode, you can enter text that will be interpreted and executed. For example, execute commands (: keys), search (/and keys) or filter commands (! Key). After the command is executed, VIM returns to the pattern before the command-line mode, usually in normal mode.
This is similar to command-line mode, where you can execute multiple commands at one time before using the: Visual command to leave the ex mode.
This is commonly used in common mode, insert mode, and command line mode, and this course covers only the three common patterns.
2. Switching of three common modes
Vim starts into normal mode, in insert mode or command line mode only need to press ESC or ctrl+[(this is not used in the VIM course environment) to enter the normal mode. In normal mode, press I (insert) or a (attach) key to enter the insert mode, in normal mode press: Enter command line mode. Enter WQ in the command line mode to save and exit vim.
Second, into the vim
1. Use the VIM command to enter the Vim interface
Vim is appended with the file name that you want to open, or that does not exist (then as a new file). Open the Xfce terminal and enter the following command
$ vim Practice_1.txt
Vim editor can also be opened using Vim directly, but no files will be opened.
$ vim
Enter command line mode: E file path can also open the corresponding file.
2. Cursor movement
After entering Vim, press the I key to enter insert mode. In this mode you can enter text information.
Press ESC to enter normal mode, using the arrow keys or the H,J,K,L key to move the cursor in this mode.
Keys |
Description |
H |
Left |
L |
Right (lowercase L) |
J |
Under |
K |
On |
W |
Move to the next word |
B |
Move to the previous word |
Try using the arrow keys in normal mode to move the cursor over the letters SHIYANLOU.
Third, enter the insertion mode
1. Enter insert mode
Use the following key in normal mode to enter insert mode, and to start typing from the corresponding position
Command |
Description |
I |
Edit at current cursor |
I |
Insert at beginning of line |
A |
Inserting at the end of a row |
A |
Insert an edit after the cursor |
O |
Insert a new row after the current row |
O |
Insert a new row before the current line |
cw |
Replace the character from the position of the cursor to the end of a word |
Iv. Saving the document
1. Save the document in command line mode
Input from Normal mode: Enter command line mode, enter W return, save document. Enter: W file name you can save the document as a different file name or save it to another path
Five. Exit vim
1. Exit vim in command line mode
Input from Normal mode: Enter command line mode, enter WQ carriage return, save and exit edit
Here are a few other ways to exit:
Command |
Description |
: q! |
Force quit, do not save |
: Q |
Exit |
: wq! |
Force Save and exit |
: W < file path > |
Save As |
: SaveAs File path |
Save As |
: X |
Save and exit |
: Wq |
Save and exit |
2. Exiting vim in normal mode
Enter SHIFT+ZZ in normal mode to save and exit vim
Vi. deletion of text
1. Delete Vim text message in normal mode
Go to normal mode and use the following commands to quickly delete text:
Command |
Description |
X |
Delete the character that the cursor contains |
X |
Delete the previous character of a cursor |
Delete |
Same as X |
Dd |
Delete entire row |
Dw |
Delete a word (not in Chinese) |
d$ or D |
Delete to end of line |
d^ |
Delete to beginning of line |
Dg |
Delete to end of document |
d1g |
Delete to document header |
In addition, you can add a number to the command before it, indicating that multiple rows are deleted at once, such as:
2DD means delete 2 rows at a time
One, VIM repeat command
1. Repeated execution of the last command
In normal mode. (decimal point) indicates that the last command operation was repeated
Copy test files to a local directory
$ cp/etc/protocols.
Open a file for editing
$ VIM Protocols
Enter x in normal mode, delete the first character, enter. (decimal point) will delete one character again, or you can repeat the delete operation of DD
2. Execute commands of the same number of times
Enter Normal mode input n<command>,n indicates the number of repetitions followed by the following exercises:
Open file file for editing
$ VIM Protocols
Below you can do the following exercises in turn:
- Enter 10x, delete 10 consecutive characters
- Enter 3DD, 3 lines of text will be deleted
In normal mode, you can also use the DW or the DAW (delete a word) to delete a word, so you can easily think of DNW (n replaced by the corresponding number ) means to delete n words
Ii. Quick jump of cursors
In normal mode, the following command allows the cursor to be quickly reversed to the specified position, we discuss the rapid implementation of the inline jump and in-line jump
1. Jump between rows
ng (n shift+g)
command /strong> |
description |
cursor moved to nth row ( If the line number is not displayed by default, enter command mode first, type : Set Nu to display line numbers ) |
gg |
cursor moved to first row |
g (shift+g) |
|
tip: After you have completed the jump, you can use the Ctrl+o quickly go back to the last time ( before jump ) cursor Position , this technique is very practical, such as when you write code, suddenly remembered a bug, need to change, this time you jump to change, just need to press Ctrl+o to return to your previous position.
2. In-line jump
In normal mode, use the following command to jump within a line in a word
Command |
Description |
W |
To the beginning of the next word |
E |
To the end of the next word |
B |
To the beginning of the first word |
Ge |
To the end of the previous word |
0 or ^ |
to the wardrobe. |
$ |
To end of line |
f< Alphabet > |
Search backwards < letters > and jump to the first matching position (very useful) |
f< Alphabet > |
Search forward < letters > and jump to the first matching position |
t< Alphabet > |
Search backwards < letters > and jump to a letter before the first matching position (not used) |
t< Alphabet > |
Search forward < letter > and jump to a letter after the first matching position (not used) |
Iii. copy, paste and cut
1. Copy and paste text
- Use Y to copy in normal mode
- In normal mode, yy copies the entire row of the cursor (3yy means copy 3 rows)
- In normal mode, y^ is copied to the beginning of the line, or y0. Does not contain the character at which the cursor is located.
- In normal mode, y$ is copied to the end of the line. The character where the light is contained.
- In normal mode, yw copies a word.
- In normal mode, y2w copies two words.
- In normal mode, YG is copied to the end of the text.
- In normal mode, y1g is copied to the beginning of the text.
- Paste with P in normal mode
- In normal mode, the P (lowercase) representation is pasted to the cursor (bottom)
- In normal mode, the P (uppercase) represents the paste to the front of the cursor (top)
2. Cut and paste
In fact, the first DD Delete command is cut, you can use p to paste each time DD deletes the contents of the document, and this allows us to implement a very refreshing function--exchange up and down line:
DDP, just so simple, that implements the fast Exchange cursor where the line is with the line below it
Information Security system design basics second week study summary