First, the experiment
1. In-depth understanding of computer systems (1) Linux Fundamentals
A.linux command
Command-option-parameter ( 选项
a switch that adjusts the execution behavior of a command, 选项
depending on whether the command is displayed differently.) 参数
refers to the object that the command is acting on. )
B.man command
Man find commands by helping documents Man-k can help us learn commands I think this command is really good for us, that is, the English version of the experimental building looks dizzy
Combined with the grep command and pipeline that you learned later, you can find multiple keywords: man-k 1 | grep Key2 | grep Key3 | ...
C.chat command
Although the man is very important, but some commands to see the help is not used, beginners need an example, cheat is the small copy of the side
(2) Linux C language Programming Foundation
A.vim
Vim or to follow the tutorial specific practice, with almost one hours to follow the tutorial practice or not very skilled, it seems to be son ah concrete practice in a lot of use in order to integrate through.
Specific VIM exercises I'll do it again with the next experiment.
b.gcc
You can compile the program and also a cross-platform compiler.
- Preprocessing: Gcc–e hello.c–o hello.i;gcc–e Call CPP
- Compilation: Gcc–s hello.i–o hello.s;gcc–s Call CCL
- Compilation: Gcc–c hello.s–o hello.o;gcc-c Call as
- Link: gcc hello.o–o hello; gcc-o call ld
C.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.
- 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
D. Practice
Using Vim to enter code
2.Vim Editor
(1) Vim Quick Start
A. Normal mode
Normal mode commands often require an operator end. For example, the normal mode command dd
deletes the current row, but the first "D" can be followed by another move command instead of the second one d
, such as a "J" key that moves 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 dj
the effect is the same. In normal mode, there are many ways to get into insert mode. The more common way is to press a
(append/append) or i
(insert/insert) key.
B. 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.
C. 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.
D. Selection mode (select modes)
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.
E. Command line 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 ( !
keys). After the command is executed, VIM returns to the pattern before the command-line mode, usually in normal mode.
F.ex mode (Ex mode)
visual
Commands can execute multiple commands at once before leaving the ex mode.
G. Mode conversion
Vim starts into normal mode, in insert mode or command line mode, just press Esc
or Ctrl+[
(this is no use in the VIM course environment) to enter normal mode. In normal mode i
, press (insert) or a
(attach) keys to enter the insert mode, in normal mode press :
enter command line mode. In the command line mode, enter the wq
carriage return and save and exit Vim.
Enter Vim
A. 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 the command line mode and the :e 文件路径
same file can be opened.
B. Cursor movement
After entering Vim, press the i
key to enter insert mode. Press Esc
Enter normal mode, use the arrow keys in this mode or,,, the h
j
k
l
Key can move the cursor.
Key |
Description |
h |
Left |
l |
Right (lowercase L) |
j |
Under |
k |
On |
w |
Move to the next word |
b |
Move to the previous word |
C. 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 |
Note that each time you go back to normal mode to switch to insert mode in a different way
D. Saving a document in command-line mode
Enter the :
command line mode from normal mode, enter w
a carriage return, and save the document. Enter to save the :w 文件名
document as a different file name or save it to another path
E.
exit vim in command line mode
Enter :
command line mode from normal mode, enter wq
return, save and exit edit
Command |
Description |
:q! |
Force quit, do not save |
:q |
Exit |
:wq! |
Force Save and exit |
:w <文件路径> |
Save As |
:saveas 文件路径 |
Save As |
:x |
Save and exit |
:wq |
Save and exit |
Out of vim in normal mode
Normal mode input Shift+zz
can be saved out of vim
Delete vim text information 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 |
Withx |
dd |
Delete entire row |
dw |
Delete a word (not in Chinese) |
d$ OrD |
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
Represents deleting 2 rows at a time
(2) Vim document editing
Vim Repeat command
A. Repeat Last Command
In normal mode .
(decimal point) means the last command operation is repeated
Copy the test file to a local directory:$ cp/etc/protocols.
Open file for editing:$ vim Protocols
Normal mode input x
, delete the first character, the input .
(decimal point) will be deleted again a character, in addition to also can be repeated dd
delete operation
B. Executing commands of the same number of times
Enter Normal mode input N<command>
, n indicates the number of repetitions followed
Open file file for editing
$ vim protocols
- Input
10x
, delete 10 consecutive characters
- Input
3dd
, 3 lines of text will be deleted
- In normal mode, you can also
dw
daw
delete a word with or (delete a word)
Quick Jump for 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
A. Inter-row jumps
Command |
Description |
nG (n shift+g) |
Cursor moves to nth row (if no line number is displayed by default, enter command mode first :set nu to display line numbers) |
gg |
Cursor moves to the first row |
G (SHIFT+G) |
To the last line |
Tip: After you have completed the jump, you can use the Ctrl+o
quick go back to the previous (before the jump) cursor position
B. 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<字母> |
Search backwards < letters > and jump to the first matching position (very useful) |
F<字母> |
Search forward < letters > and jump to the first matching position |
t<字母> |
Search backwards < letters > and jump to a letter before the first matching position (not used) |
T<字母> |
Search forward < letter > and jump to a letter after the first matching position (not used)
|
G Jump to the end of the document, 9G jump to the Nineth line, 9DD to delete 9 lines; GG delete a row; G jumps to the end of the document;
- In normal mode, jump to a line, use
w
jump to the beginning of a word, and then use dw
the word delete
- In normal mode, use
e
jump to the end of a word and use ~
the letter that contains the cursor to capitalize or lower case
Copy paste and cut
A. Copying and pasting text
B. Cut and paste
dd
The delete command is cut, and you dd
can use it to paste each time you delete the contents of the document, p
which allows us to implement a very refreshing function-the exchange of the upper and lower lines:
ddp
, so simple, that it implements the fast Exchange cursor where the line is with the line below it
(3) Find and replace
substitution and revocation of characters (undo action)
A. Replace and revoke (undo) command
Both the Replace and undo commands are for normal mode operations
C
command |
description |
r +< Replace letter ; |
replaces the letter that contains the cursor with the specified letter |
R |
Replace continuously until you press ESC |
cc |
replace Entire row, which deletes the row of the cursor and enters insert mode |
cw |
replace one word, delete one word, and enter insert mode |
td> (uppercase)
replace cursor later to end of line |
~ |
Invert cursor case |
u {n} |
undo once or N operations |
U (uppercase) |
undo all modifications to the current line |
ctrl+r |
Redo, which is the action of undoing undo |
- Input
11G
, jump to 11 lines
- Enter FA to jump to the first
a
character
- Input
r
, and the input b,a character is replaced by the B character (practical)
- Enter a
R
replacement character, enter a new string, press ESC to return to normal mode (useful)
- Enter
cc
replace whole line character, enter new string, press ESC to return to normal mode after entering
- Enter
cw
replace one English word (word), press ESC to return to normal mode (useful)
- Input
~
, the case of the character in which the rollover cursor is located
- The input is
C
replaced with the end of the line, that is, the word will be replaced after the cursor is in place, press ESC to return to normal mode
- Enter
u
undo Last action
Fast Indent
A. Using commands to quickly adjust indent operations
- Normal mode input
15G
, jump to 15 lines
- Input entire line in normal mode
>>
indent right (used to format code super cool)
- Enter the entire line in normal mode to the
<<
left fallback
- Enter
:
command-line mode to set values in normal mode to shiftwidth
control the number of characters in indentation and fallback shiftwidth command
b.shiftwidth
Command
Refers to >>
the indentation (which can be abbreviated) from the previous command. sw
enter :
command line mode to shiftwidth
set values to control the number of characters in indent and fallback to get the current set value
:set shiftwidth?
Set indent to 10 characters
:set shiftwidth=10
Enter ESC
back into normal mode and try again to >>
see if the indent changes
C. Adjusting the text position
Command line mode enter :ce
(center) command to center the contents of the bank
Command line mode enter :ri
(right) command to make our text
Command line Mode enter: le
(left) command to leave the contents of the bank
Find A. Quick Find
Enter Normal mode /
and then type the string you want to find and press ENTER to find it. ?
is the same as the /
function, but ?
looks up and /
down. After entering the lookup, the input n
and N
can continue to find n
the expression to continue the lookup, N
reverse Lookup
B. Quick Find Exercises
Use VIM to open a file for editing
$ vim protocols
- Normal mode input
/icmp
find string ICMP
- Normal mode Enter to
n
find the next ICMP
- Normal mode input
?tcp
up lookup string TCP
- Normal mode input
N
to find the last occurrence of TCP
C. Advanced Search
- Enter
\*
a word in normal mode to find where the cursor is located
- Normal mode input
\#
Ibid, but \*
forward (up) to find, #则是向后 (bottom) find
- Normal mode
g\*
\*
, but partially matches the word
- Normal mode
g\#
\#
, but partially matches the word
Search for n
The above, N
continue to find command can still be used
(4) Getting Started with advanced features
Multi-file editingA. Editing multiple files with vim
There are two forms of editing multiple files, one being a parameter that is used before entering Vim is multiple files. Another is to enter vim and then edit the other files. Create two new files and edit them simultaneously
$ vim 1.txt 2.txt
Default Access 1.txt
to file editing interface
- Command line mode input
:n
edit 2.txt file, you can !
:n!
Force switch, the input of a file is not saved, just switch to another file
- Command line mode input
:N
edit 1.txt file, can be !
forced to :N!
switch, the input in the previous file is not saved, just switch to another file
B. Open a new file after entering Vim
- Command line mode enter
:e 3.txt
open new file 3.txt
- Command line mode input
:e#
back to the previous file
- command-line mode input
:ls
to list previously edited documents
- Command line mode input
:b 2.txt
(or number) can be directly into the file 2.txt edit
- Enter
:bd 2.txt
(or number) in command-line mode to delete a file item from a previously edited list
- Command line mode input
:e! 4.txt
, new open file 4.txt, discard the file being edited
- Enter
:f
The file name you are editing in command line mode
- Input in command line mode
:f new.txt
, change the file being edited name to New.txt
C. Recovering files
If the document is not saved due to a power outage, you can use the recovery method, enter the vim -r
document, input :ewcover 1.txt
to restore
$ vim -r 1.txt
Visual ModeA. Introduction to Visual mode commands
- Enter in normal mode
v
(lowercase), enter the character selection mode, you can move the cursor, where the cursor will be selected. The selection is deselected when the V-meeting is pressed again.
- In normal mode input
Shift+v
(lowercase), enter the line selection mode, press V will be the entire row selection, you can move up and down the cursor select more rows, again, press once Shift+v
can be deselected.
- In normal mode
Ctrl+v
(lowercase), this is the area selection mode, you can select the rectangular region, and then cancel the selection by one time Ctrl+v
.
- Enter
d
Delete selection area in normal mode
- Enter
y
Copy selection area contents in normal mode
B. Visual mode command practice
- In normal mode
9G
, jump to line 9th, enter Shift+v
(lowercase v), enter the visual mode for row selection, select 5 rows, press >>
indent, indent 5 rows into oneshiftwidth
- Enter in normal mode
Ctrl+v
(lowercase v), enter visual mode for rectangular area selection, select the first column character and then x
delete the whole column
Windows OperationsA. Introduction to Windows Operations
Vim can open multiple windows in one interface for editing, which are called Vim windows. There are many ways to open the method, for example, you can use the input command line mode to :new
open a new Vim window, and enter the window to edit a new file
Normal mode Ctrl+w
can also be entered, but it Ctrl+w
will conflict with Chrome's shortcut key to close the tab page.
- Command-line mode enter
:sp 1.txt
open new Landscape window to edit 1.txt
- Command-line mode
:vsp 2.txt
to open a new vertical window to edit 1.txt
Ctrl-w s
split the current window into two horizontal windows in normal mode
Ctrl-w v
split the current window into two vertical windows in normal mode
- In normal mode
Ctrl-w q
, it is: Q ends the split window. If you have input in a new window, you need to use the mandatory character! namely: q!
Ctrl-w o
Open a window in normal mode and hide all previous windows
Ctrl-w j
move to the following window in normal mode
Ctrl-w k
move to the upper window in normal mode
Ctrl-w h
move to the left window in normal mode
Ctrl-w l
move to the right window in normal mode
Ctrl-w J
move the current window below in normal mode
Ctrl-w K
move the current window to the top in normal mode
Ctrl-w H
move the current window to the left in normal mode
Ctrl-w L
move the current window to the right in normal mode
Ctrl-w -
reduce the height of the window in normal mode
Ctrl-w +
increase the height of the window in normal mode
B. Windows operation exercises
Open the practice file$ vim 1.txt
- command-line mode input
:new
open a new vim window
- Command-line mode enter
:sp 2.txt
open new Landscape window to edit 2.txt
- Command-line mode enter
:vsp 3.txt
open new Landscape window to edit 3.txt
- If you use a non-Chrome browser, you can use
Ctrl+w
the jump between windows
- Enter
:q!
exit multi-window editing in command-line mode of different windows
Document EncryptionA. Creating an encrypted document
$ vim -x file1
Enter your password to confirm the password so that the next time you open, VIM will ask you to enter the password
executing external commands in vim
Enter command-line mode !
to execute external shell commands
:!ls
Used to display the contents of the current directory
:!rm FILENAME
Used to delete a file named filename
:w FILENAME
Save the file you are editing in the current VIM as a filename file
Help Systemview Help in A.vim
- Press
F1
vim
to open your own preset help document in normal mode
- Enter
:h shiftwidth
shiftwidth
The open Help file in command line mode
- Input
:ver
display version and parameters in command line mode
function SettingA.vim function Setting
Can be set when editing the file function settings, such as the command line mode input :set nu
(display number of lines), set value exit Vim will not be saved. To permanently save the configuration, you need to modify the Vim configuration file. Vim configuration file ~/.vimrc
, you can open the file for modification, but be careful not to affect the normal use of vim
B. Get the current settings
- Enter
:set
or :se
display all modified configurations in command line mode
- command-line mode input
:set all
displays all the SetPoint values
- Command-line mode
:set option?
to enter a setting value that displays option
- Command line mode to enter the
:set nooption
cancel current set value
description of the C.set function
:set autoindent(ai)
automatic indentation of input settings in command line mode
- Command line mode input
:set autowrite(aw)
set AutoArchive, default not open
- Enter or in command line
:set background=dark
mode light
, set the background style
- Command line mode input
:set backup(bk)
set automatic backup, default not open
- Command line mode input
: set cindent(cin)
set C language style indent
3.Linux System Programming
(1) Use of GCCcompiler use of GCC
Second, the problems encountered and sentiment:
Early groping vim time with too much, followed the tutorial done two times, think some instructions still do not remember, sad~
In the test and run the teacher layout code, I first put a few code to change the file name and save, but there is no way to call a few code to each other, and the book is very obscure, difficult to read.
When I was doing the experiment building GDB use, is not able to read the experimental instruction book content, such as: "GDB start, you can add some gdb start switch, the detailed switch can be used gdb-help view"
Do not know how to add the start switch and so on, I hope that teachers can be more involved in class, after all, the compiler is also a necessary tool for programming ^_^
Information Security system design basics second week study summary