Linux foundation day02

ChinaManor 2021-04-09 13:21:03
linux foundation day02 day


VI Editor _ Terminal editor ( Focus, focus, etc )

The goal is

  1. vi brief introduction
  2. Open and create new files
  3. Three working modes
  4. Common command query

1 brief introduction

1.1 Study vi Purpose

  • At work , Right On the server file Conduct Simple Modification of , have access to ssh Log on to the remote server , And use vi Editor Simply edit it
  • The documents to be modified include
    • Source code
    • The configuration file
      • for example : tomcat The configuration file for the server
      • for example : Configuration file of network card information

    In the absence of a graphical interface , To edit a file , vi Is the best choice Every use linux The programmer , We should learn more or less vi Common commands

1.2 vi and vim

1.2.1 VI

  • vi yes visual interface For short , yes linux in The most classic Text editor for
  • vi Of Core design ideas
    • Keep the programmer's fingers on the keyboard Core area , You can do all the editing
  • vi Characteristics
    • Only editors Text content , Not right typeface Arrange paragraphs
    • Mouse operation not supported
    • No menu
    • Only the command
  • vi The editor is in System management Server management When editing a file , Its function can never be compared with the editor of graphical interface

1.2.2 VIM

viM It's from vi Developed text editor , Support Code completion 、 compile And Wrong jump And other convenient programming functions , Widely used in programmers , go by the name of The God of editor

2 Open and create new files

  • Input in the terminal vim Keep up with file name that will do
vim file name 
  • If the file already exists , Will open the file directly
  • If the file doesn't exist , When saving and exiting Will create a new file
1 vim No filename for
2 Edit content
2.1 Output a line of statements
2.2 Copy and paste 2.1 Content 19 Time
2.3 Save and exit
3 see 

Be careful : This section focuses on open and New file , Other orders will be explained later

2.1 Open the file and locate the line

  • In daily work , You may encounter opening a file , And navigate to the case of the specified row
  • for example : In development is , Know that a line of code has errors , Sure Rapid positioning To the location where the error code came out
  • This is the time , You can use the following command to open a file
vim file name + Row number 

Tips : If you only take + Instead of specifying the line number , Will go directly to the end of the file

2.2 VI Three working modes

  • VI There are three working modes
  1. Command mode
    • Open the file first into command mode , It's using vi Of entrance
    • adopt command Routine editing of files , for example location Page turning Copy Paste Delete … …
    • In other graphic editors , adopt Shortcut key perhaps mouse Operations implemented , All in Command mode achieve
  2. Last row mode – perform preservation sign out Wait for the operation
    • To exit vi Back to the console , You need to enter a command in last line mode
    • Last row mode yes vi Of exit
  3. Edit mode – Normal editing text

2.4 Last mode command

command

english

function

w

write

preservation

q

quit

sign out , If you don't save it , You are not allowed to exit

q!

quit

To force out of , Exit without saving

wq

write & quit

Save and exit ( Don't go in the mode )

x

Save and exit ( Don't go in the mode )

ZZ

Save and exit ( Command mode )

3 Common commands

Learning tips

  1. vi More orders , Don't expect to remember everything at once , Individual orders forget , It just affects the editing speed . In the use of vi On command , Be careful Turn off Chinese IME

3.1 Move

Use it skillfully vi, First of all, we should learn how to In command mode Move the cursor quickly Edit operation command Can be used with mobile commands

1) On Next Left Right

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-q1padSsY-1600335607914)(F:/%E4%BC%A0%E6%99%BA%E6%92%AD%E5%AE%A2/%E4%BC%A0%E6%99%BA%E4%B8%93%E4%BF%AE%E5%AD%A6%E9%99%A2/1812/01linux/%E8%AE%B2%E4%B9%89/02_%E6%89%93%E5%8C%85%E5%8E%8B%E7%BC%A9_vim%E7%BC%96%E8%BE%91%E5%99%A8_%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86_%E7%94%A8%E6%88%B7%E6%9D%83%E9%99%90/%E7%AC%94%E8%AE%B0/assets/1558278451153.png)]

command

function

finger

h

towards the left

index finger

j

Down

index finger

k

Up

Middle finger

l

towards the right

ring finger

2) Move in line

command

english

function

w

word

Move a word back

b

back

Move a word forward

0

Head of line

^

Head of line , The first position is not a blank character

$

At the end of the line

3) Rows move

command

english

function

gg

go

Top of file

G

go

end of file

Numbers gg

go

Move to Numbers Number of corresponding lines

Numbers G

go

Move to Numbers Number of corresponding lines

: Numbers

Move to the number corresponding to Row number

4) Screen movement

command

english

function

Ctrl + b

back

Page up

Ctrl + f

forward

Page down

H

Head

At the top of the screen

M

Middle

In the middle of the screen

L

Low

At the bottom of the screen

3.2 Move ( Program )

1) Paragraph move

  • vim Use in Blank line To distinguish paragraphs
  • Program development , Usually A piece of function related code will be written together – There is no blank line between Command function { Last paragraph } Next paragraph

2) Bracket toggle

  • In the world of programs , **()、[]、{}** The usage rate is very high , and They come in pairs . Command function % Bracket matching and switching

3.3 Select the text ( Visual Modes )

  • Study Copy Before the command , We should learn to How to choose Code to copy
  • stay vi Choose the text , Need to show visual Command switch to Visual Modes
  • vi Provided in Three Visual Modes , It's easy for programmers to choose How to select text
  • Press ESC You can give up the selection , Back to Command mode

command

Pattern

function

v

Visual Modes

Select the text in normal mode from the cursor position

V

Visualization mode

Select the full line the cursor passes through

Ctrl + v

Visual block mode

Select text vertically

  • In visual mode , You can talk to Mobile command Continuous use , for example ggVG can Select all the content

3.4 Revocation and reinstatement of revocation ( Life saving order )

Before learning editing commands , First of all, you need to know how to undo the previous FALSE Edit operation

command

english

function

u

undo

Revoke the last order (ctrl + z)

Ctrl + r

uredo

To resume an order of revocation

3.5 Delete text

command

english

function

x

cut

Delete the character where the cursor is , Or the selected text

d( Mobile command )

delete

Delete the content corresponding to the move command

dd

delete

Deletes the line where the cursor is located , Sure ndd Delete multiple lines

D

delete

Delete to end of line

Tips : If you use Visual Modes A text has been selected , So no matter what you use d still x, Can delete the selected text

Delete command can be used with move command , Here are the common combined commands :

command

effect

dw

Delete from cursor position to end of word

d0

Delete from cursor position to the beginning of a line

d}

Delete from cursor position to end of paragraph

ndd

Delete continuously from the cursor down n That's ok

3.6 Copy and cut

  • vi There is a Buffer for copied text
    • Copy The command saves the selected text in the buffer
    • Delete Command deleted text will be saved in the buffer
    • Where needed , Use Paste Command to insert the text of the buffered pair into the cursor position

command

english

function

y( Copy command )

copy

Copy

yy

copy

Duplicate a row , Sure nyy Copy many lines

d( Cut command )

delete

shear

dd( shear )

delete

Cut a line , Sure ndd shear n That's ok

p

paste

Paste

Tips :

  • command d 、x Similar to the graphic interface Cut operation – ctrl + x
  • command y Be similar to Graphic interface Copy operation – Ctrl + C
  • command p Similar to the graphic interface Paste operation – Ctrl + v
  • vi There is only one text buffer in , If I do it later Copy 、 Cut operation , The contents of the previous buffer will be replaced .

Be careful

  • vi Medium Text buffer and Systematic Shear plate Not the same
  • So use... In other software Ctrl + C Copied content , Can no longer vi Pass through p Command paste
  • Can be in Edit mode Next use Right click to paste

3.7 Replace

command

english

function

Working mode

r

replace

Replace the current character

Command mode

R

replace

Replace the character after the current line cursor

Replace mode

  • R Orders can enter Replace mode , When the replacement is complete , Press down ESC , Press down ESC You can go back to Command mode
  • Replace the command The function of is not to enter Edit mode , On the file Lightweight modifications

3.8 lookup

Regular search

command

function

/str

lookup str

  • After finding the specified content , Use Next Find the next place to appear
    • n : Find the next one
    • N : Find the last one
  • If you don't want to see highlights , You can find any content that does not exist in a file
  • Word quick match

command

function

*

Find the word of the current cursor backward

#

Look forward to the word where the current cursor is

  • In development , Quickly match words , You can quickly see that this word has been used in other places

3.9 Find and replace

  • stay vi Find and replace commands in Last row mode perform
  • Memory command format
:%s///g
  1. Global replacement
  2. Visual area replacement
  • Select first To replace the words Range
  • The command format is as follows
:s/ Old text / New text /g
  1. Confirm replacement

c confirm confirm

  1. y - yes Replace
  2. n - no Do not replace
  3. a - all Replace all
  4. q -quit Quit replacing
  5. l - last the last one , And move the cursor to the beginning of the line
  6. ^E Scroll down
  7. ^Y Scroll up

3.10 Insert command ( important )

  • stay vi In addition to common i Get into Edit mode Outside , The following command is also provided to enter editing mode

command

english

function

Commonly used

i

insert

Insert text before current character

Commonly used

I

insert

Insert text at the beginning of the line

More commonly used

a

append

Add text... After the current character

A

append

Add text at the end of the line

More commonly used

o

Insert a blank line after the current line

Commonly used

O

Insert a blank line before the current line

Commonly used

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-FrqwODyv-1600335607923)(F:/%E4%BC%A0%E6%99%BA%E6%92%AD%E5%AE%A2/%E4%BC%A0%E6%99%BA%E4%B8%93%E4%BF%AE%E5%AD%A6%E9%99%A2/1812/01linux/%E8%AE%B2%E4%B9%89/02_%E6%89%93%E5%8C%85%E5%8E%8B%E7%BC%A9_vim%E7%BC%96%E8%BE%91%E5%99%A8_%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86_%E7%94%A8%E6%88%B7%E6%9D%83%E9%99%90/%E7%AC%94%E8%AE%B0/assets/1558543477231.png)]

3.11 practice

rehearse 1 – Edit command and Digital combination

  • In development , Continuous input may be encountered N The same characters
  • for example : ********** continuity 10 asterisk

To achieve this effect can be found in Command mode Next

  1. Input 10, To repeat 10 Time
  2. Input i Get into Edit mode
  3. Input * That is, repeated words
  4. Press down ESC return Command mode , After returning vi It will The first 2、3 Repeat the two steps 10 Time

Tips : In normal development , stay Before entering edit mode , Don't press the number

Search command

2.find Search for

preparation
Switch directories to /export/ And Empty content

cd /export/ && rm -rf /export/* && tree

New directory And Toggle directory And The new file

mkdir -p /export/aaa/bbb/ccc/ddd/eee/ touch /export/aaa/bbb/ccc/ddd/eee/abc.txt touch /export/aaa/123.txt touch /export/aaa/312.txt

see /export Contents of the catalog

tree /export

The goal is

  • adopt find command In a specific directory ( Include its descendant Directory ) Search for eligible The file of

2.1 route

  • First step : Search the specified directory , File is abc.txt The file of
  • The second step : Search the specified directory , file name contain 1 The file of
  • The third step : Search the specified directory , All with .txt File with extension
  • Step four : Search the specified directory , In numbers 1 Opening file

2.2 Realization : In the specified directory By name Search for

  • Command format

Serial number

Command format

effect

01

find [ route ] -name ‘*.txt’

Find the extension under the specified path is .txt The file of , Include subdirectories

  • If the path is omitted , Indicates to search under the current folder
  • Wildcards learned before , In the use of find It can be used at the same time
  • First step : Search the specified directory , File is abc.txt The file of
# =================== Achieve the goal ============================
# Mode one : Specify the full catalog
find /export/ -name 'abc.txt'
# Mode two : Current directory
find . -name 'abc.txt'
# Mode three : Current directory Sure Omit Don't write
find -name 'abc.txt'
  • The second step : Search the specified directory , file name contain 1 The file of
# ================= preparation ===============
# 1 Create test file
touch /export/12.txt /export/616.txt /export/321.txt
# ================= Implementation Directory ===============
find /export/ -name "*1*"
  • The third step : Search the specified directory , All with .txt File with extension
find /export/ -name "*.txt"
  • Step four : Search the specified directory , In numbers 1 Opening file
find /export -name "1*"

2.3 Summary

  • adopt find [path] -name "*1*" Finish searching files by name

Unzip command

  • preparation
# Empty the contents of the specified directory
cd /export/ && rm -rf *
# Create test file
touch 1.txt 2.txt 3.txt
# Create a test directory with content
mkdir -p /export/aaa/
touch /export/aaa/4.txt /export/aaa/5.txt
# View results
tree /export

The goal is

  • From a third party download Compressed package , After decompression The installation to Server [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-LyFIlOPp-1600335607929)(assets/1558527865552.png)]
  • adopt Packaging compression Backup file

jar : java rar java Compression package for project

war : web rar web Compression package for project

route

  • 2.1 First step : pack and Unpack
  • **2.2 The second step : Packaging compression and Unpack and decompress **

3. Realization

3.1 First step : pack and Unpack

3.1.1 pack

  • Like will Winter clothes Put it in bag
  • Big files after packing Need to be .tar ending .

tar pack Command format

# take A series of documents Pack it up A large file
tar -cvf Package name .tar Packed Directory
tar -cvf Package name .tar Packed files 1 Packed files 2 Packed files 3

tar Option description

command

english

meaning

c

create

Generate files , Create package file

v

verbosely( Long winded )

image ‘ Tang's monk ’ Report progress as well

f

file

Specify the file name of the file , f There must be .tar file , So we have to put it in the back left

 practice 1: take 1.txt、2.txt、3.txt Pack it up 123.tar file
practice 2: There will be content aaa Catalog Pack it up aaa.tar file 

3.1.2 Unpack

  • Like will Winter clothes from Take it out of the bag

tar Unpack Command format

# Pack one up Decompose into A series of small papers , The decomposition position is Current directory
tar -xvf Package name .tar
# Pack one up Decompose into A series of small papers , The decomposition position is Specify the directory
tar -xvf Package name .tar -C Unpack path location 

command

english

meaning

x

extract ( extract )

Unpack

C ( Capitalization C)

directory ( Catalog )

Save to current directory by default , adopt -C Change the extraction Directory , Be careful : The unzip directory must exist

 practice 1: take 123.tar Unzip to In the current directory
practice 2: take aaa.tar Unpack to /export/test/a1/b1/c1/ Directory 

Summary

 pack : tar -cvf File name after packing .tar Packed directory or filename
Unpack : tar -xvf File name after packing .tar [ -C Specify the unpacking location ]

3.2 The second step : Use gzip Format Compress and decompression

  • pack and Compress There are two things
  • Similar to First put the winter clothes in the compression bag , Then draw out the air
  • stay Linux in , The most commonly used compressed file format is xxx.tar.gz
  • stay tar There is an option in the command -z You can call gzip , Thus, it is convenient to realize the functions of compression and decompression

The command format is as follows

# Compressed files
tar -zcvf Package compressed file name .tar.gz Compressed files / Catalog
# Unzip the file ( Memory tips : Specializing in prestige )
tar -zxvf Package files .tar.gz
# Extract to the specified path
tar -zxvf Package files .tar.gz -C Directory path 

tar Description of the options

command

english

meaning

z

gzip

Use gzip Compression and decompression

j

bzip2

Use bzip2 Compression and decompression

 practice 1: take 1.txt、2.txt、3.txt Pack and compress into 123.tar.gz file (gzip Compressed format )
practice 2: There will be content aaa Catalog Pack it up aaa.tar.gz file (gzip Compressed format )
practice 3: take 123.tar.gz Unzip to In the current directory (gzip Compressed format )
practice 4: take aaa.tar.gz Unpack to /export/bbb Directory (gzip Compressed format )

Summary

 Packaging compression : tar -zcvf File name after packing .tar.gz Packed compressed directory or filename
Unpack and decompress : tar -zxvf File name after packing .tar.gz [ -C Specify the unpacking location ]

3.3 The third step : Use bzip2 Format Compress and decompression

  • bzip It's the second way to compress
  • Similar to First put the winter clothes in the compression bag , Then draw out the air
  • stay Linux in , bzip2 The compressed file format is xxx.tar.bz2
  • stay tar There is an option in the command -j You can call bzip2 , Thus, it is convenient to realize the functions of compression and decompression

The command format is as follows

# Compressed files
tar -jcvf Package compressed file name .tar.bz2 Compressed files / Catalog
# Unzip the file ( Performance Weifang )
tar -jxvf Package files .tar.bz2
# Extract to the specified path
tar -jxvf Package files .tar.bz2 -C Directory path 

tar Description of the options

command

english

meaning

z

gzip

Use gzip Compression and decompression

j

bzip2

Use bzip2 Compression and decompression

 practice 1: take 1.txt、2.txt、3.txt Pack and compress into 123.tar.bz2 file (bzip2 Compressed format )
practice 2: There will be content aaa Catalog Pack it up aaa.tar.bz2 file (bzip2 Compressed format )
practice 3: take 123.tar.bz2 Unzip to In the current directory (bzip2 Compressed format )
practice 4: take aaa.tar.bz2 Unzip to /export/bbb Directory (bzip2 Compressed format )

Summary

 Packaging compression : tar -jcvf File name after packing .tar.bz2 Packed compressed directory or filename
Unpack and decompress : tar -jxvf File name after packing .tar.bz2 [ -C Specify the unpacking location ]

To turn it off

halt

restart

reboot

4 User authority related commands

The goal is

  • understand user and jurisdiction Basic concepts of
  • User management Terminal command
  • Group management Terminal command
  • Modify the permissions Terminal command

Basic concepts of users and permissions

4.1 Basic concepts

  • user yes Linux An important part of the system work , User management includes user And Group management
  • stay Linux In the system , Whether it is by the local or remote login system , Every system You have to have an account , also Have different permissions for different system resources
  • Yes file / Catalog The authority of includes :

Serial number

jurisdiction

english

abbreviation

Number sequence number

01

read

read

r

4

02

Write

write

w

2

03

perform

execute

x

1

04

No authority

-

0

  • stay Linux in , You can specify Every user in the light of Different files or directories Of Different authorities

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-K2iDgASE-1600335607939)(assets/1558581559021.png)]

4.2 Group

  • To facilitate user management , Put forward Group The concept of , As shown in the figure below [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-M1f8BDLD-1600335607944)(assets/1558487112521.png)]

4.3 ls -l Expand

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-ihr9ZkzT-1600335607947)(assets%5CUsers%5CAdministrator%5CAppData%5CRoaming%5CTypora%5Ctypora-user-images%5C1570973470529.png)]

  • ls -l You can view the details of the files in the folder , From left to right In turn, is :
    • jurisdiction , If the first character is d Presentation directory
    • Hard link number , Generally speaking, there are many ways , You can access the current directory and files
    • The owner , Home directory file / Mulan road The owners of are usually The current user
    • Group , stay linux in , A lot of times , The group name... Appears and user name The same thing , Subsequent speak
    • size
    • Time
    • name

    [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-iuTHXHgk-1600335607949)(assets/1558487141422.png)] [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-C7Qk0xsD-1600335607953)(assets/1558583116607.png)]

4.4. Group management Terminal command

The essence : to Same type of users Assign permissions

Serial number

command

effect

01

groupadd Group name

add group

02

groupdel Group name

Delete the group

03

cat /etc/group

Confirm group information

04

chgrp Group name file / Directory name

Modify file / The group to which the catalog belongs

Tips :

  • Group information is stored in /etc/group In file
  • /etc The directory is designed to hold System configuration information The catalog of
  • in application , Can target in advance Group Set permissions , then Add different users to the corresponding groups , thus You don't have to set permissions for each user in turn

Objectives of the drill

  1. stay Under specified directory establish aaa Catalog
  2. newly build dev Group
  3. take aaa The group of the directory is changed to dev

4.5. User management Terminal command

(1) Create user / Set the password / Delete user

command

effect

explain

useradd -m -g Group New user name

Add new user

-m Automatically create user home directory -g Specify the group of users , Otherwise, a group with the same name will be created

passwd user name

Set user password

If it is an ordinary user , Direct use passwd You can change your account password

userdel -r user name

Delete user

-r Option will automatically delete the user's home directory

cat /etc/passwd | grep user name

Confirm user information

After creating a new user , User information will be saved in /etc/passwd In the folder

Tips :

  • Creation time , If you forget to add -m Option to specify the new user's home directory – The easiest way is Delete user , Recreate
  • When you create a user , A and... Are created by default user name Homonymous Group name
  • User information is stored in /etc/passwd In file

/etc/passwd The file stores the user's information , from 6 A well-organized 7 Messages , Namely

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-2sOZgshU-1600335607956)(assets/1558487197175.png)]

  1. user name
  2. password (x, Means encrypted password )
  3. UID ( User logo )
  4. GID( Group logo )
  5. User's full name or local account number
  6. Home directory
  7. Login using Shell, After login , Terminal commands used

(2) View user information

Serial number

command

effect

01

id [ user name ]

To view the user UID and GID Information

02

who

View a list of all currently logged in users

03

whoami

View the account name of the current login user

(3) su Switching users

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-jxz2xMAo-1600335607960)(assets/1558614565424.png)]

  • because Ordinary users Some permissions cannot be used , So we need to Switching users

Serial number

command

effect

explain

01

su - user name

Switching users , And the planning catalog

- You can switch to the user's home directory , Otherwise keep the position

02

exit

Exit the current login user

  • su No user name , You can switch to root , But it is not recommended , Because it's not safe
  • exit The schematic diagram is as follows :

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-y5lV09kB-1600335607965)(assets/1558487219340.png)]

(4) sudo

  • although adopt su -u root You can switch to root user , however There is a serious Safe hidden trouble
  • linux In the system root Account number usually For system maintenance and management , All resources of the operating system Have access rights
  • If you don't use it carefully rm -rf ... ... , It could paralyze the system
  • In most versions of linux in , None of them recommend Just use root Account login system
  • sudo A command is used to execute a command in another capacity , The pre-set identity is root
  • The user to use sudo when , You have to enter the password first , after 5 Minutes of validity , If the time limit is exceeded, you must re-enter the password Tips : If its unauthorized user attempts to use sudo, A warning email will be sent to the administrator

(4.1) to Designated user grant jurisdiction

  • The essence : notice The server to Specific users Distribute Temporary administrator rights

vim /etc/sudoers

# Default exists : root user With all the authority
root ALL=(ALL) ALL
# grant zhangsan user All authority
zhangsan ALL=(ALL) ALL 

(4.2) Use user zhangsan Sign in , Operation manager command

  • The essence : Use temporary administrator privileges
# Don't switch root user , It can also be done Add user features
sudo useradd -m -g dev zhaoliu

preparation : Use root The user action

# Empty the contents of the directory
rm -rf /export/*
# Create a test directory
mkdir -p /export/aaa/
# Create test file
touch /export/aaa/01.txt /export/aaa/02.txt
# View the contents of the specified directory
tree /export

(5). Modify user rights

Serial number

command

effect

01

chmod

Modify the permissions

5.1 Mode one : Modify user rights

Goal drill :

# 1. Use root Delete the readability of the directory Can write Executable rights
# 2. Use Other users such as zhangsan Can't switch to This directory
# 3. Use root Increase the execution permission of the directory , Again Use zhangsan Try switching to the directory 

5.2 Mode two

  • although Mode one Directly modifying file | Catalog Of read | Write | perform jurisdiction , But it can't be accurate to The owner | Group | other jurisdiction
  • The command format is as follows :( u Indicates the user / g Indicates the group / o Means something else )
chmod -R u=rwx,g=rx,o=rwx file | Catalog 

Serial number

jurisdiction

english

abbreviation

Number sequence number

01

read

read

r

4

02

Write

write

w

2

03

perform

execute

x

1

04

No authority

-

0

Goal drill :

# 1 Use root User give User assignment Can be read 、 Can write 、 Executable jurisdiction ,
Subordinate to the group Distribute Can be read 、 Executable jurisdiction ,
others Distribute Can be read 、 Executable jurisdiction 

5.3 Mode three : Simplify way two

  • The command format is as follows :
chmod -R 755 file | Catalog 
  • explain The first number yes Owner permissions , The second number yes Group permission , The third number yes Other user privileges

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-8klXSWqb-1600335607967)(assets/1558487247085.png)]

The usual combinations of numbers are ( u Represent user / g Represents a group / o Means something else )

  • 777 ===> u=rwx, g=rwx, o=rwx
  • 755 ===> u=rwx, g=rx, o=rx
  • 644 ===> u=rw, g=r, o=r

Goal drill :

# 1 Use root User give User assignment Can be read 、 Can write 、 Executable jurisdiction ,
Subordinate to the group Distribute Can be read 、 Executable jurisdiction ,
others Distribute Can be read 、 Executable jurisdiction 

System information related commands

  • The main purpose of this section is to facilitate the maintenance of servers through remote terminals , View current on server System date and time / Disk space usage / Procedure execution
  • In this summary, terminal commands are query commands , Use these commands to understand the usage of system resources

The goal is

  • Time and date
    • date
    • cal
  • Disk and directory space
    • df
    • du
  • Process information
    • ps
    • top
    • kill

1. Time and date

1.1 date Time

command

effect

date

View system time ( Default )

date +"%Y-%m-%d %H:%M:%S"

View system time ( Specify the format )

date -s “ Time string ”

Set system time

First step : Display current time

# Display time
date
# Display the time in the specified format
date +"%Y-%m-%d %H:%M:%S"

The second step : Set system time

date -s " Time string "

1.2 cal The calendar

Serial number

command

effect

01

cal

View the calendar of the current month

02

cal -y

Check the calendar for the current year

03

cal 2020

see 2020 The calendar of the year

04

cal 10 2020

see 2020 year 10 The calendar of the month

02. Disk information

Serial number

command

effect

01

df -h

disk free Show disk free space

02

du -h [ Directory name ]

disk usage Display the directory size under the directory

  • Option description

Parameters

meaning

-h

Display the file size in a human way

03. Process information

  • So-called process , Generally speaking, it means A process currently executing

Serial number

command

effect

01

ps aux

process status View process details

02

top

Dynamic display of running processes and sorting

03

kill [-9] Process code

Terminate the specified process -9 To terminate forcibly

ps By default, only applications launched by the current user through the terminal will be displayed

  • ps Option description function Meaning of options a Display all processes on the terminal , Include other users' processes u Show the detailed status of the process x Display the process without control terminal Tips : Use kill On command , It's best to terminate only the processes started by the current user , And don't stop root The process of identity opening , Otherwise, the system may crash
  • To exit top You can input q

top

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-e7TgLHXa-1600335607971)(assets%5CUsers%5CAdministrator%5CAppData%5CRoaming%5CTypora%5Ctypora-user-images%5C1570978034994.png)]

us User space occupancy CPU percentage
sy Kernel space footprint CPU percentage
ni User process space changes the priority of the process occupation CPU percentage
id Free CPU percentage
wa Waiting for input and output CPU Time percentage
hi Hardware interrupt
si Software interrupt
st: real time 

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-VTUQd6IT-1600335607978)(assets%5CUsers%5CAdministrator%5CAppData%5CRoaming%5CTypora%5Ctypora-user-images%5C1570978332697.png)]

PID Process number USER user name PR priority NI nice value . Negative value indicates high priority , A positive value indicates a low priority m RES Used by process 、 Physical memory size not swapped out , Company kb SHR Shared memory size , Company kb S Process status . D= Uninterrupted sleep R= function S= sleep T= track / stop it Z= Zombie process %CPU CPU Usage rate %MEM Percentage of physical memory used by the process TIME+ Used by process CPU Total time , Company 1/100 second COMMAND Executed command

Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .

版权声明
本文为[ChinaManor]所创,转载请带上原文链接,感谢
https://javamana.com/2021/04/20210409130927649Z.html