Linux - practical articles
- foreword
- Basic introduction to vi and vim
- Three modes commonly used by vi and vim
- Basic use of vi and vim
- Mutual switch between various modes
- vi and vim shortcut keys
- Shutdown & Restart Command
- User login and logout
- Basic introduction to user management
foreword
Basic introduction to vi and vim
Linux 系统会内置 vi 文本编辑器
Vim has the ability of program editing, which can be regarded as an enhanced version of Vi. It can actively identify the correctness of grammar by font color, which is convenient for program design. The convenient programming functions such as code completion, compilation and error jump are particularly rich and widely used among programmers.
Three modes commonly used by vi and vim
normal mode
Opening a file with vim directly enters the normal mode (this is the default mode). In this mode, you can use the "Up, Down, Left, and Right" keys to move the cursor, you can use "Delete Characters" or "Delete Entire Line" to process the file content, and you can also use "Copy, Paste" to process your file data.
insert mode
Press any letter such as i, I, o, O, a, A, r, R, etc. to enter the edit mode. Generally speaking, just press i.
command line mode
Enter esc and then enter: In this mode, you can provide you with relevant instructions, and the actions of reading, saving, replacing, leaving vim, displaying line numbers, etc. are achieved in this mode!
Basic use of vi and vim
Use vim to develop a Hello.java program, save it. Step description and demonstration
Mutual switch between various modes
vi and vim shortcut keys
small test:
- Copy the current line yy, copy the 5 lines 5yy below the current line, and paste (enter p).
- Delete the current line dd, delete the current line down 5 lines 5dd
- Find a word in the file [under the command line/keyword, press Enter to search, enter n to find the next one]
- Set the line number of the file and cancel the line number of the file.[In the command line: setnu and :setnonu]
- Edit the /etc/profile file, in normal mode, use shortcut keys to the last line [G] and the first line [gg] of the document
- Enter "hello" in a file, in normal mode, and then undo this action u
- Edit the /etc/profile file, in general mode, and move the cursor to, enter 20, and then enter shift+g
- See more organized documentation
- Keyboard mapping for shortcut keys
Shutdown & Restart Command
basic introduction
shutdown | –h | now | It's time to shut down |
---|---|---|---|
shudown | -h | 1 | "hello, it will shut down in 1 minute" |
shutdown | –r | now | restart your computer now |
halt | NULL | NULL | Shut down, the effect is the same as above |
reboot | NULL | NULL | restart your computer now |
sync | NULL | NULL | Synchronize data in memory to disk |
Attention to detail
-
Regardless of restarting the system or shutting down the system, first run the sync command to write the data in the memory to the disk
-
The current shutdown/reboot/halt and other commands have been synced before shutdown
User login and logout
basic introduction
- When logging in, try to log in with the root account as little as possible, because it is the system administrator with the greatest authority to avoid operational errors. You can use ordinary users to log in, and then use the "su-username" command to switch to the system administrator status
- Enter logout at the prompt to log out the user
usage details
- The logout logout command has no effect in graphical runlevels, but is valid in runlevel 3.
- The concept of run level will be introduced later
Basic introduction to user management
The Linux system is a multi-user and multi-tasking operating system. Any user who wants to use system resources must first apply for an account from the system administrator, and then log into the system as this account.
Add user
basic grammar
useradd username
Applications
Case 1: Add a user milan, the default home directory of the user is /home/milan
Details
- When the user is successfully created, a home directory with the same name as the user will be automatically created
- You can also specify the new user name of the directory through useradd-d, and specify the home directory for the newly created user
Specify/change password
basic grammar
passwd username
Applications
Specify the password passwd for milan.
milan
is supplemented to display the directory pwd where the current user is located.
delete users
basic grammar
userdel username
Applications
- Delete user milan, but keep the home directory, userdel milan
- Delete users and user home directories, such as tom, userdel-r tom
Query user information command
basic grammar
id username
Applications
Case: Please query root information
#id root
switch user
In operating Linux, if the current user's authority is not enough, you can use the su- command to switch to a user with high authority, such as root
basic grammar
su - switch username
Applications
Create a user jack, specify a password, and switch to jack
Details
- Switching from a user with high authority to a user with low authority does not require entering a password, and vice versa.
- When you need to return to the original user, use the exit/logout command
View current user/login user
Basic grammar
whoami/ who am I
user group
Similar to roles, the system can manage multiple users with commonality/permissions in a unified manner
new group
Command: groupadd group name
delete group
Command (basic syntax): groupdel group name
Case presentation
- Add groups directly when adding users
- Command (basic syntax): useradd–g user group user name
- Add a user zwj, directly assign him to wudang
- group add wudang
- useradd-g wudang zwj
Modify a user's group
Instruction (basic syntax): usermod–g user group user name
case demonstration
Create a group mojiao
and put zwj into mojiao
Instruction: usermod-g mojiao zwj
User and group related files
/etc/passwd file
The configuration file of the user (user), which records various information of the user
The meaning of each line: username: password: user identification number: group identification number: commentary description: main directory: login shell
/etc/shadow file
password configuration file
/etc/group file
The meaning of each line: login name: encrypted password: last modified time: minimum interval: maximum interval: warning time: inactivity time: expiration time: flag