Learning note 0316 --- basic commands of Linux

Posted by Cell0518 on Tue, 11 Jan 2022 04:03:50 +0100

linux basic commands

preview contents

2.1 / 2.2 system directory structure 2.3 ls command 2.4 document type 2.5 alias command 2.6 relative and absolute paths 2.7 cd command 2.8 creating and deleting the directory mkdir/rmdir 2.9 rm command 2.10 environment variable PATH 2.11 cp command 2.12 mv command 2.13 document viewing cat/more/less/head/tail 2.14 file and directory permissions chmod 2.15 change owner and group chown 2.16 umask

1.linux system directory analysis

[root@linux-01 ~]# ls /
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr

Serial number

catalogue

explain

1

/root

Home directory of root user

2

/home

User's home directory

3

/boot

System startup related files

4

/etc

Path of configuration file

5

/bin

"Soft connection" / usr/bin; Store user commands

6

/sbin

"Soft connect" / usr/sbin: stores the commands of the root user

7

/lib

"Soft connect" / usr/lib: library file

8

/lib64

"Soft connect" / usr/lib64: library files

9

/usr

User's file: / usr/local/nginx

10

/dev

Equipment Directory: CD, hard disk, mouse, keyboard

11

/mnt

Temporary mount directory

12

/proc

System process directory

13

/run

Temporary files generated by some processes will disappear after restart

14

/srv

File generated by service

15

/tmp

System temporary directory,

16

/var

/var/log storage system log

17

/media

Media directory

18

/opt

Used to install additional packages

19

/sys

System kernel related files

2.ls command (list)

2.1 the command ls -l lists the details of the file

[root@linux-01 ~]# ls -l
 Total consumption 4
-rw-------. 1 root root 1420 3 January 14:02 anaconda-ks.cf

[root@linux-01 ~]# ll
 Total consumption 4
-rw-------. 1 root root 1420 3 January 14:02 anaconda-ks.cfg

*

ls -l

Command details

*

-rw-------.

The first column represents the file permissions: file type, file owner permissions, file group permissions, and other permissions

*

1

The second column indicates that several files use the same inode

*

root

The root in the third column represents the file owner

*

root

The root in the fourth column represents the group to which the file belongs

*

1420

The fifth column represents the file size in B

*

March

The sixth column represents the time month

*

14

The seventh column represents time and day

*

01:02

The eighth column represents time, hours and minutes

*

anaconda-ks.cfg

The ninth column represents the file name

2.2 the command ls -i (i is – inode) displays the inode number of the file

[root@linux-01 ~]# ls -i   #View the inode number of the file
16797763 anaconda-ks.cfg

## What is inode?
understand inode,Start with file storage.
Files are stored on the hard disk. The smallest storage unit of the hard disk is called"a sector"(Sector). Each sector stores 512 bytes (equivalent to 0.5KB). 
When the operating system reads the hard disk, it will not read sectors one by one, which is too inefficient. Instead, it reads multiple sectors continuously at one time, that is, one sector at a time"block"(block). This method is composed of multiple sectors"block",Is the smallest unit of file access."block"The most common size is 4 KB,Eight consecutive sector Form a block. 
File data is stored in"block"Obviously, we must also find a place to store the meta information of the file, such as the creator of the file, the creation date of the file, the size of the file, and so on. This area for storing file meta information is called inode,The Chinese translation is"Index node". 
Each file has a corresponding inode,It contains some information related to the file

##  To view inode information, use the command stat
[root@linux-01 ~]# stat anaconda-ks.cfg    
  File:"anaconda-ks.cfg"
  Size: 1420      	Block: 8          IO Block: 4096 normal files
 Equipment: 803 h/2051d	Inode: 16797763    Hard link: 1
 jurisdiction:(0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Environmental Science: system_u:object_r:admin_home_t:s0
 Recent visit: 2019-03-14 01:02:30.554024559 +0800
 Recent changes: 2019-03-14 01:02:30.557024559 +0800
 Recent changes: 2019-03-14 01:02:30.557024559 +0800
 Created on:-

2.3 the command ls -lh (h is – human readable) displays file information more humanized

[root@linux-01 ~]# ls -lh
 Total consumption 4.0K
-rw-------. 1 root root 1.4K 3 January 14:02 anaconda-ks.cfg

2.4 the command ls -la (a yes – all) shows hidden files

##  The files starting with the dot are hidden files or directories##
[root@linux-01 ~]# ls -la
 Total consumption 28
dr-xr-x---.  3 root root  147 3 February 14:40 .  #Indicates the current directory. 3 indicates that there are three file price folders under the root directory with the same inode number
dr-xr-xr-x. 17 root root  224 3 January 14:01 ..
-rw-------.  1 root root 1420 3 January 14:02 anaconda-ks.cfg
-rw-------.  1 root root  864 3 January 15:41 .bash_history
-rw-r--r--.  1 root root   18 12 September 29, 2013 .bash_logout
-rw-r--r--.  1 root root  176 12 September 29, 2013 .bash_profile
-rw-r--r--.  1 root root  176 12 September 29, 2013 .bashrc
-rw-r--r--.  1 root root  100 12 September 29, 2013 .cshrc
drwx------.  2 root root   80 3 January 15:41 .ssh
-rw-r--r--.  1 root root  129 12 September 29, 2013 .tcshrc
##  The third column in the second column of the root folder represents the same inode of the three folders   
[root@linux-01 ~]# ls -i /root
16797763 anaconda-ks.cfg
[root@linux-01 ~]# ls -i .
16797763 anaconda-ks.cfg
[root@linux-01 ~]# ls -i .ssh/..
16797763 anaconda-ks.cfg

2.5. ls -lta is sorted by modification time. The latest time is in the top and the earliest time is in the bottom

[root@linux-01 ~]#  ls -lta
 Total consumption 28
-rw-------.  1 root root  864 3 January 15:41 .bash_history
drwx------.  2 root root   80 3 January 15:41 .ssh
dr-xr-x---.  3 root root  147 3 February 14:40 .
-rw-------.  1 root root 1420 3 January 14:02 anaconda-ks.cfg
dr-xr-xr-x. 17 root root  224 3 January 14:01 ..
-rw-r--r--.  1 root root   18 12 September 29, 2013 .bash_logout
-rw-r--r--.  1 root root  176 12 September 29, 2013 .bash_profile
-rw-r--r--.  1 root root  176 12 September 29, 2013 .bashrc
-rw-r--r--.  1 root root  100 12 September 29, 2013 .cshrc
-rw-r--r--.  1 root root  129 12 September 29, 2013 .tcshrc

2.7 ls -ld (d is – directory) lists the directory itself, not the contents of the directory

[root@linux-01 ~]# ls -ld  /
dr-xr-xr-x. 17 root root 224 3 January 14:01 /

[root@linux-01 ~]# ls -l /
Total consumption 16
lrwxrwxrwx.   1 root root    7 3 14:00:57 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 3 January 14:04 boot
drwxr-xr-x.  19 root root 3200 3 14 / 22:22 dev
drwxr-xr-x.  74 root root 8192 3 14 / 22:23 etc
drwxr-xr-x.   2 root root    6 4 November 2018 home
lrwxrwxrwx.   1 root root    7 3 14:00:57 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 3 14:00:57 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 4 November 2018 media
drwxr-xr-x.   2 root root    6 4 November 2018 mnt
drwxr-xr-x.   2 root root    6 4 November 2018 opt
dr-xr-xr-x. 108 root root    0 3 14 / 22:22 proc
dr-xr-x---.   3 root root  147 3 February 14:40 root
drwxr-xr-x.  23 root root  620 3 14 / 22:22 run
lrwxrwxrwx.   1 root root    8 3 14:00:57 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 4 November 2018 srv
dr-xr-xr-x.  13 root root    0 3 14 / 22:22 sys
drwxrwxrwt.  10 root root  236 3 March 16:14 tmp
drwxr-xr-x.  13 root root  155 3 14:00:57 usr
drwxr-xr-x.  19 root root  267 3 January 14:03 var

2.8 ll = ls -l --color=auto

In the figure below, we can see the use of alias command

2.9. file type

File properties

file type

explain

The first attribute is [-]

Common file type

One of the most file types in Linux, including plain text files (ASCII); Binary; Data format file (data); Various compressed files

The first attribute is [l]

Link file

Similar to the shortcut under Windows.

The first attribute is [d]

Catalog file

You can use the cd command to enter

The first attribute is [b]

Fast device file

It is an interface device that stores data for system access. In short, it is a hard disk. For example, the code of hard disk 1 is / dev/hda1 and other files.

The first attribute is [c]

Character device file

That is, the interface device of the serial port, such as keyboard, mouse, etc.

The first attribute is [s]

s socket

Such files are usually used for network data connections. You can start a program to listen to the requirements of the client, and the client can communicate data through the socket.

The first attribute is [p]

Pipeline file

FIFO is also a special file type. Its main purpose is to solve the errors caused by multiple programs accessing a file at the same time. FIFO is the abbreviation of first in first out.

[root@linux-01 ~]# ll /root/anaconda-ks.cfg 
-rw-------. 1 root root 1420 3 January 14:02 /root/anaconda-ks.cfg

[root@linux-01 ~]# ll -d /root/.ssh/
drwx------. 2 root root 80 3 January 15:41 /root/.ssh/

[root@linux-01 ~]# ll -d /bin 
lrwxrwxrwx. 1 root root 7 3 14:00:57 /bin -> usr/bin

[root@linux-01 ~]# ll /dev/tty
crw-rw-rw-. 1 root tty 5, 0 3 14 / 22:33 /dev/tty

[root@linux-01 ~]# ll /dev/sda
brw-rw----. 1 root disk 8, 0 3 14 / 22:22 /dev/sda

[root@linux-01 ~]# ll -a /dev/log 
srw-rw-rw-. 1 root root 0 3 14 / 22:22 /dev/log

3. alias command

## View all aliases in the system
[root@linux-01 ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
## The which command is also an alias. Which finds whether the command is found in the PATH
[root@linux-01 ~]# which which
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
	/usr/bin/alias
	/usr/bin/which	
## echo input system environment variable
[root@linux-01 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
## Customize an alias
[root@linux-01 ~]# alias xihaji='ls -lah'
[root@linux-01 ~]# xihaji
 Total consumption 28 K
dr-xr-x---.  3 root root  147 3 February 14:40 .
dr-xr-xr-x. 17 root root  224 3 January 14:01 ..
-rw-------.  1 root root 1.4K 3 January 14:02 anaconda-ks.cfg
-rw-------.  1 root root  864 3 January 15:41 .bash_history
-rw-r--r--.  1 root root   18 12 September 29, 2013 .bash_logout
-rw-r--r--.  1 root root  176 12 September 29, 2013 .bash_profile
-rw-r--r--.  1 root root  176 12 September 29, 2013 .bashrc
-rw-r--r--.  1 root root  100 12 September 29, 2013 .cshrc
drwx------.  2 root root   80 3 January 15:41 .ssh
-rw-r--r--.  1 root root  129 12 September 29, 2013 .tcshrc

[root@linux-01 ~]# which xihaji
alias xihaji='ls -lah'
	/usr/bin/ls	

## Cancel alias use unalias	
[root@linux-01 ~]# unalias xihaji 
[root@linux-01 ~]# xihaji
-bash: xihaji: Command not found

4. Relative path, absolute path, cd and pwd commands

Absolute path refers to the path starting from the '/' directory; The relative path does not start under the '/' directory.

## Absolute path
[root@linux-01 ~]# ls /root/anaconda-ks.cfg 
/root/anaconda-ks.cfg

## Relative path
[root@linux-01 ~]# ls anaconda-ks.cfg 
anaconda-ks.cfg

## cd (change directory) refers to entering a directory
[root@linux-01 ~]# cd /etc/sysconfig/

## pwd displays the current directory
[root@linux-01 sysconfig]# pwd
/etc/sysconfig

## cd - enter the last directory
[root@linux-01 sysconfig]# cd  -
/root
[root@linux-01 ~]# pwd
/root
[root@linux-01 ~]# cd  -
/etc/sysconfig
[root@linux-01 sysconfig]# pwd
/etc/sysconfig
[root@linux-01 sysconfig]# cd  -
/root
[root@linux-01 ~]# pwd
/root

##  cd and cd ~ indicate entering the current user's home directory
[root@linux-01 ~]# cd 
[root@linux-01 ~]# pwd
/root
[root@linux-01 ~]# cd ~
[root@linux-01 ~]# pwd
/root

## cd  ..   Enter the upper level directory
[root@linux-01 ~]# cd 
[root@linux-01 ~]# cd ..
[root@linux-01 /]# pwd
/
[root@linux-01 /]# cd ..
[root@linux-01 /]# pwd
/

5. Create and delete directories (mkdir, rmdir)

## mkdir (make directory) creates a directory
[root@linux-01 /]# mkdir /tmp/test
[root@linux-01 /]# ls -d /tmp/test/
/tmp/test/

## mkdir creates multiple level by level directories. If the parent directory of the created subdirectory does not exist, the creation will fail
[root@linux-01 /]# mkdir /tmp/test/1/2/3
mkdir: Unable to create directory"/tmp/test/1/2/3": There is no such file or directory

## mkdir -p can create multiple directories in succession
[root@linux-01 /]# mkdir -p /tmp/test/1/2/3

## MKDIR - PV V stands for visualization. You can see the process of creating a directory
[root@linux-01 /]# mkdir -pv /tmp/test/2/3/4
mkdir: Directory created "/tmp/test/2"
mkdir: Directory created "/tmp/test/2/3"
mkdir: Directory created "/tmp/test/2/3/4"
## rmdir (remove directory) can only delete empty directories
[root@linux-01 /]# ls -d tmp/test/1/2/3/
tmp/test/1/2/3/
[root@linux-01 /]# rmdir tmp/test/1/2/3/  #Delete directory 3
[root@linux-01 /]# ll tmp/test/1/2/  #You can see that directory 3 has been deleted
 Total consumption 0
[root@linux-01 /]# 


## rmdir -p deletes the level by level directory. As long as the subdirectory exists, deleting the parent directory will report an error
[root@linux-01 /]# rmdir /tmp/test/1
rmdir: delete "/tmp/test/1" fail: directory not empty

6. Delete command rm and display tree in tree

## rm can delete files and directories
[root@linux-01 2]# rm  /tmp/test/1/2/1.txt 
rm: Delete normal empty file "/tmp/test/1/2/1.txt"?y  #Enter y to delete
[root@linux-01 2]# ll
 Total consumption 0
[root@linux-01 2]# 

## rm -f (f stands for -- force) ignore nonexistent files and parameters without prompting
[root@linux-01 2]# rm /tmp/test/1/2/
1.txt  2.txt  
[root@linux-01 2]# rm -f /tmp/test/1/2/*
[root@linux-01 2]# ll
 Total consumption 0

## rm -r() recursively deletes directories and their contents
[root@linux-01 ~]# rm -r /tmp/test/
rm: Enter directory"/tmp/test/"? yy
rm: Enter directory"/tmp/test/1"? y
rm: Enter directory"/tmp/test/1/2"? y
rm: Delete directory "/tmp/test/1/2/3"?y
rm: Delete directory "/tmp/test/1/2"?y
rm: Delete directory "/tmp/test/1"?y
rm: Enter directory"/tmp/test/2"? y
rm: Enter directory"/tmp/test/2/3"? y
rm: Enter directory"/tmp/test/2/3/4"? y
rm: Delete normal empty file "/tmp/test/2/3/4/1.txt"?y
rm: Delete normal empty file "/tmp/test/2/3/4/2.txt"?y
rm: Delete directory "/tmp/test/2/3/4"?y
rm: Delete directory "/tmp/test/2/3"?y
rm: Delete directory "/tmp/test/2"?y
rm: Delete directory "/tmp/test/"?y

## rm -rf can be deleted recursively without asking
## Tree file path can display the files under this path, and the tree is displayed
[root@linux-01 2]# tree /tmp/test/
/tmp/test/
├── 1
│   └── 2
└── 2
    └── 3
        └── 4

5 directories, 0 files


## ! tree  ! Represents the result of the last use of the command tree 
[root@linux-01 2]# !tree
tree /tmp/test/
/tmp/test/
├── 1
│   └── 2
└── 2
    └── 3
        └── 4

5 directories, 0 files
[root@linux-01 2]# 

7. Environment variable PATH

## View the location of the system variable ##
[root@linux-01 ~]# echo $PATH 
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

[root@linux-01 ~]# cp /usr/bin/ls  /tmp/ls2
[root@linux-01 ~]# ls2      #The copied command is not added to the system environment variable, so it cannot be used
-bash: ls2: Command not found
[root@linux-01 ~]# /tmp/ls2 
anaconda-ks.cfg


[root@linux-01 ~]# PATH=$PATH:/tmp/   #You can add the tmp directory to the system environment variable for temporary effect
[root@linux-01 ~]# which ls2
/tmp/ls2
[root@linux-01 ~]# ls2
anaconda-ks.cfg


[root@linux-01 ~]# vi /etc/profile  #If you want to be permanent, you can modify this file
 Add at the end of the file line: PATH=$PATH:/tmp/

[root@linux-01 ~]# !echo
echo $PATH 
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/ls2:/tmp/
[root@linux-01 ~]#

##If you want to delete the added environment variable, you can do the following##
[root@linux-01 ~]# PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:
[root@linux-01 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

8. Copy command cp

## see cp Command location ##
[root@linux-01 ~]# which cp
alias cp='cp -i'
	/usr/bin/cp
[root@linux-01 ~]# mkdir -p /tmp/1/2
[root@linux-01 ~]# mkdir -p /tmp/test/1/2
[root@linux-01 ~]# rm -rf !$     # !$  Represents the last parameter of the last command
rm -rf /tmp/test/1/2 
[root@linux-01 ~]# tree /tmp/test/   # You can see that the 2 directory has been deleted
/tmp/test/
└── 1

1 directory, 0 files
[root@linux-01 ~]# cp /tmp/test/  /tmp/test1/   # The - r parameter needs to be added to copy the directory
cp: Skip directory"/tmp/test/"
[root@linux-01 ~]# cp -r /tmp/test/  /tmp/test1/
[root@linux-01 ~]# tree /tmp/test1/
/tmp/test1/
└── 1

1 directory, 0 files
[root@linux-01 ~]# cp -r /tmp/test/  /tmp/test1/  #If the copied directory already exists, the copied directory is placed under this directory
[root@linux-01 ~]# tree  /tmp/test1
/tmp/test1
├── 1
└── test
    └── 1

3 directories, 0 files

9. Move command mv

## see mv location ##
[root@linux-01 ~]# which mv  
alias mv='mv -i'
	/usr/bin/mv	

## If the source file is moved under this directory, it means rename ##
[root@linux-01 ~]# ll
 Total consumption 4
-rw-------. 1 root root 1420 3 January 14:02 anaconda-ks.cfg
[root@linux-01 ~]# mv anaconda-ks.cfg anaconda-ks.cfg.1
[root@linux-01 ~]# ll
 Total consumption 4
-rw-------. 1 root root 1420 3 January 14:02 anaconda-ks.cfg.1

## If the moved directory exists under the subdirectory of the target file, the moved file overwrites the subdirectory of the target file ##
[root@linux-01 ~]# tree /root/
/root/
├── anaconda-ks.cfg.1
├── xihaji
│   └── 1.txt
└── xihaji1
    └── xihaji

3 directories, 2 file
[root@linux-01 ~]# mv xihaji/ xihaji1/
mv: Overwrite"xihaji1/xihaji"? y
[root@linux-01 ~]# !tree
tree /root/
/root/
├── anaconda-ks.cfg.1
└── xihaji1
    └── xihaji
        └── 1.txt

2 directories, 2 files

10. Document viewing commands cat (tac flashback), more, less, head, tail

## cat View the file and display all the contents of the file ##
[root@linux-01 ~]# cat 1.txt 
1
2
3
## tac Flashback view file ##
[root@linux-01 ~]# tac 1.txt 
3
2
1·
## more View the file, display the file contents screen by screen, and turn the screen with the space bar ##
## less see file  ##
/String: the ability to drill down to "string"

?String: the ability to search up for "string"

n: Repeat the previous search (and / or ? (related)

N: Reversely repeats the previous search (and / or ? (related)

b  Turn back one page

d  Turn back half a page

h  Display help interface

Q  sign out less command

u  Scroll forward half a page

y  Scroll forward one line

Space bar to scroll one line

Press enter to scroll through the page

[pagedown]:  Turn down one page

[pageup]:    Turn up a page
## head View the information at the beginning of the file,-n Option add number ##
## tail  -f  Dynamic display of file information, mostly used to view logs, you can view the following figure ##

11. File and directory permissions chmod

[root@linux-01 ~]# ll
 Total consumption 12
-rw-r--r--. 1 root root    6 3 June 16-20:15 1.txt
-rw-r--r--. 1 root root  363 3 June 16-23:49 2.txt
-rw-------. 1 root root 1420 3 January 14:02 anaconda-ks.cfg.1

Permission decomposition

meaning

-(authority of position 1)

The representative file is an ordinary file (mentioned above for the file type)

r w - (represents 2, 3 and 4 permission positions respectively)

Permissions on behalf of the owner (read, write, execute)

--- (representing 5, 6 and 7 permission positions respectively)

Permissions (read, write, execute) on behalf of the group

--- (representing 8, 9 and 10 permission positions respectively)

Authority on behalf of others (read, write, execute)

-

-The representative has no authority

(authority on behalf of the 11th)

When selinux is turned on, this will be generated by creating a file

[root@linux-01 ~]# r=4  w=2  x=1   rwx=7  rw-=6   r-x=5  --r=1
## Several ways to modify file permissions ##
[root@linux-01 ~]# ll
 Total consumption 12
-rw-r--r--. 1 root root    6 3 June 16-20:15 1.txt
-rwx------. 1 root root  363 3 June 16-23:49 2.txt
-rw-------. 1 root root 1420 3 January 14:02 anaconda-ks.cfg.1
[root@linux-01 ~]# chmod 777 2.txt 
[root@linux-01 ~]# ll 2.txt 
-rwxrwxrwx. 1 root root 363 3 June 16-23:49 2.txt

[root@linux-01 ~]# chmod a-x  2.txt 
[root@linux-01 ~]# !ll
ll 2.txt 
-rw-rw-rw-. 1 root root 363 3 June 16-23:49 2.txt


[root@linux-01 ~]# chmod a+x 2.txt 
[root@linux-01 ~]# !ll
ll 2.txt 
-rwxrwxrwx. 1 root root 363 3 June 16-23:49 2.txt


[root@linux-01 ~]# chmod o-x 2.txt 
[root@linux-01 ~]# !ll
ll 2.txt 
-rwxrwxrw-. 1 root root 363 3 June 16-23:49 2.txt


[root@linux-01 ~]# chmod  u=rwx,g=r,o=r 2.txt 
[root@linux-01 ~]# !ll
ll 2.txt 
-rwxr--r--. 1 root root 363 3 June 16-23:49 2.txt
## chmod -R 755  File batch modify file permissions ##
[root@linux-01 ~]# ll -d /root/xihaji/
drwxr-xr-x. 2 root root 19 3 June 17 00:44 /root/xihaji/
[root@linux-01 ~]# ll !$
ll /root/xihaji/
Total consumption 4
-rw-r--r--. 1 root root 6 3 June 16-20:15 1.txt


## No -R  Only the permissions of the folder were modified ##
[root@linux-01 ~]# chmod 755 /root/xihaji/
[root@linux-01 ~]# ll -d /root/xihaji/
drwxr-xr-x. 2 root root 19 3 June 17 00:44 /root/xihaji/
[root@linux-01 ~]# ll  /root/xihaji/
Total consumption 4
-rw-r--r--. 1 root root 6 3 June 16-20:15 1.txt

## Both file permissions and file permissions have been modified ##
[root@linux-01 ~]# chmod -R 755 /root/xihaji/
[root@linux-01 ~]# ll -d /root/xihaji/
drwxr-xr-x. 2 root root 19 3 June 17 00:44 /root/xihaji/
[root@linux-01 ~]# ll  /root/xihaji/
Total consumption 4
-rwxr-xr-x. 1 root root 6 3 June 16-20:15 1.txt

12. File owner and group permission settings chown

[root@linux-01 ~]# ll 2.txt 
-rwxr--r--. 1 root root 363 3 June 16-23:49 2.txt
[root@linux-01 ~]# chown xihaji 2.txt  #Modify owner to user xihaji
[root@linux-01 ~]# !ll
ll 2.txt 
-rwxr--r--. 1 xihaji root 363 3 June 16-23:49 2.txt
[root@linux-01 ~]# chown :xihaji 2.txt  #Modify the group to xihaji
[root@linux-01 ~]# ll 2.txt 
-rwxr--r--. 1 xihaji xihaji 363 3 June 16-23:49 2.txt
[root@linux-01 ~]# chown xihaji:root 2.txt  #The modification owner is xihaji and the group is root
[root@linux-01 ~]# !ll
ll 2.txt 
-rwxr--r--. 1 xihaji root 363 3 June 16-23:49 2.txt


## front chmod Permission design to-R Options, chown Also-R Option, which can be understood as recursion ##
[root@linux-01 ~]# chown -R USERNAME:GROUPNAME FILENAME

13. umask setting permissions for default folders and files

What is umask? When we log in to the system, creating a file always has a default permission. How does this permission come from? This is what umask does. Umask sets the default permission for users to create files, which is just opposite to the effect of chmod. Umask sets the permission "complement", while chmod sets the file permission code. Generally, it can be found in / etc/profile, / etc/bashrc, [home] / bash_ profile, [HOME]/.profile or

## System default umask Yes 022, the created folder has 755 permissions, and the created file has 644 permissions ##
[root@linux-01 ~]# umask
0022
[root@linux-01 ~]# mkdir 123
[root@linux-01 ~]# touch 111.txt

[root@linux-01 ~]# ll 111.txt 
-rw-r--r--. 1 root root 0 3 January 17:32 111.txt
[root@linux-01 ~]# ll -d 123/
drwxr-xr-x. 2 root root 6 3 January 17:32 123/
## umask If 003, what are the permissions for the new folder and file? ##
[root@linux-01 ~]# umask 003

[root@linux-01 ~]# mkdir 111
[root@linux-01 ~]# touch 123

[root@linux-01 ~]# ll 123
-rw-rw-r--. 1 root root 0 3 January 17:35 123
[root@linux-01 ~]# ll -d 111
drwxrwxr--. 2 root root 6 3 January 17:35 111
########################################
Why?

umask 003,Permissions are(-wx)
Folder permissions:( rwxrwxrwx)- (-------wx) = (rwxrwxr--) That's 774

File permissions:( rw-rw-rw-)- (-------wx) =(rw-rw-r--) That's 664

(No permission) minus (with this permission)=((still no permission)
########################################

After class summary

1. File system

Let's collect a directory structure chart, which Mr. a Ming shared. linux system directory diagram

According to my understanding of linux, I think the following directories are not commonly used:

/Boot / system boot directory; /sys / system kernel related directories; /proc / system process directory; /run / system generates temporary file directory; /bin / user command directory /sbin/ root user command directory /lib / Library Directory /lib64 / Library Directory, configuration file directory /Media / media mount directory /mnt / temporary mount directory

If there are not commonly used directories, there must be commonly used ones, which are listed below: /Root / home directory of root user; /Home / user's home directory; /tmp / temporary file directory; /The var/ log directory stores logs; /opt / third party software directory; /etc / service configuration directory /usr/

2. Some knowledge points

2.1 rsync

Rsync(remote synchronize)Is a remote data synchronization tool LAN/WAN Quickly synchronize files between multiple hosts. Rsync Use the so-called“ Rsync The "algorithm" synchronizes the files between the local and remote hosts. This algorithm only transmits different parts of the two files, rather than the whole copy every time, so the speed is quite fast
Rsync Most classes are supported Unix System, whether Linux,Solaris still BSD It has been well tested
 In addition, it is in windows There are also corresponding versions under the platform, such as cwRsync and Sync2NAS Other tools

2.2 PATH

In class, I asked Mr. a Ming this question: under the user directory Is bashrc an environment variable? The teacher said no, this file is a configuration file.

##  PATH is the environment variable of the system

Question 1: how to modify system environment variables?
Answer: modify /etc/profile

Question 2: PATH Is it a catalog collection?
answer: PATH Is a collection of directories for commands.

2.3 operation and maintenance keywords

## Most operation and maintenance work is designed to a keyword. It's shell programming.

What is? shell Programming?
in my opinion shell Programming is a collection of commands.

Other programming languages: python  go ,Necessary skills to learn in the future.

2.4 GET new words

jumpserver Fortress machine , this is a tool for automatic operation and maintenance.