Linux basics must know and know (2)

1. Linux file permission management

1、dr-xr-xr-x. 4 root root 4096 Jul 22 09:24 boot

  • The first column: what operations different users can do with the boot file
  • Second column: the number of links to the file
  • The third column: which user owns the file, usually called the owner of the file
  • The fourth column: which user group the file belongs to, usually called the file’s group
  • The fifth column: the size of the file, in bytes. 1kb=1024byte, 1mb=1024kb
  • The sixth column: the creation date or the last modification date of the file
  • Seventh column: the name of the file

2. The Linux file system will be divided into three categories according to the user's operation permissions on the file

  • The owner of the file (user)
  • The group to which the file belongs (group)
  • Other users (other)

3、d rwx r-x r-x

  • The first character indicates the type of file
    • "D" means a directory
    • "-" means it is a file
    • "L" means it is a linked file
  • The next 9 characters, every 3 characters are a group, there are 3 groups in total
    • The first group: describes what operation permissions the owner of the file has
    • The second group: describes the file's owning group users which operation permissions have on the file
    • The third group: describes what operation permissions other users have on the file
  • The meaning of authority
    • "R" means to have read permission, short spelling of read
    • "W" means to have write permission, short spelling of write
    • "X" means that you have execute permission, a short spelling of execute
    • "-" means that the corresponding location permission is not available

4. Command to modify permissions

  • Use the chmod command to modify file permissions

  • The owner of the chmod command file or the group user of the file and the root user have permission to use

  • chmod u+r file1 #Add read permission to the owner of the file

  • chmod gw file1 #The group user of the file removes the write permission

  • chmod o+x file1 #Add execution permissions to other users of the file

  • chmod a+r file1 #Add read permission to all users

    • "U" -> indicates the owner of the file
    • "G" -> indicates the group user of the file
    • "O" -> means other users
    • "A" -> means all users

5. Digital representation of file permissions

  • “r” - 4
  • “w” - 2
  • “x” - 1
  • “-” - 0
# 举例:
rwxrwxr-- 774
rwxrw-r-- 764
  • Permission to modify files using digital methods
    • chmod 774 file1
    • chmod 764 file1

6. The owner user who modified the file

  • Example 1: chown zhangsan file1
  • Example 2: chown root:root file1 #Modify the owner and group of the file at the same time
  • The chown command can only be used by the root user

7. Modify the group of the file

  • chgrp zhangsan file1
  • The chgrp command can only be used by the root user

Two, vi/vim editor explanation

1. The function is similar to the notepad in the windows operating system for editing files

2. The operations of vi and vim are the same, vim is just an upgraded version of vi

3. The vi editor has three modes

  • Command line mode (when a file is opened by default, it is in command line mode)
  • Edit mode (in the command line mode, press the letter i to enter the edit mode, the word "–INSERT–" is displayed at the bottom. Press esc to exit the edit mode)
  • Last line mode (in the command line mode, press shift +: it will enter the last line mode, with ":" displayed at the bottom)

4. Operation in command line mode

  • Delete: Press the d letter twice to delete the line where the cursor is
  • Undo: Press the letter u to undo the operation
  • Copy: Press the y letter twice to copy the line where the cursor is
  • Paste: paste the copied content by letter p
  • Cut: Press the d letter twice to cut the line where the cursor is
  • Copy multiple lines: Before using the copy command, first press the number of lines to be copied
  • Delete multiple rows: Before using the delete command, first press the number of rows to be deleted
  • Move cursor quickly
  • Press g twice to move the cursor to the head of the file
  • Press G (shift + g) to move the cursor to the end of the file
  • Enter edit mode
    • Press i to enter edit mode
    • Press A (shift + a) to enter edit mode, and the cursor moves to the end of the line
  • Save and exit: press shift + zz

5. Operation in edit mode

  • The editing mode is the same as using Notepad to edit files
  • Press Esc to exit edit mode

6. Operation in the last line mode

  • Display line number: set nu or number
  • Text replacement: 1,$s/nologin/666/g
    • 1 represents the starting line
    • $ Means the last line
    • s means replace
    • /nologin indicates the content to be replaced
    • /666 means replacement content
    • /g replace all
  • Exit: q
  • Force exit: q!
  • Save and exit: wq
  • Exit the last line mode (enter the command line mode)
    • Press Esc

Three, find command explanation

1. Function: Find files according to search conditions
2. Search according to file names

#命令格式:find [搜索范围] [-name -iname] 关键字
#示例1:#搜索根目录下,文件名是init的所有文件(注意:这里不是模糊搜索)
find / -name init	 	
#示例2:#搜索根目录下,文件名包含init的所有文件(模糊搜索)
find / -name *init*	
#示例3:#搜索根目录下,文件名以init开头的所有文件(模糊搜素)
find / -name init*	
#示例4:#搜索根目录下,文件名以init结尾的所有文件(模糊搜素)
find / -name *init	
#示例5:#搜索根目录下,文件名是init的所有文件(注意:严格区分大小写,忽略大小写使用-iname选项)
find /tmp -name init	
#示例6:##搜索根目录下,文件名是init的所有文件(注意:忽略大小写)
find /tmp -iname init	

3. Search for files based on file size

  • Command format: find [search range] [-size] file size (unit is data block)
  • Unit data block
    • The size of a data block is 512 bytes
    • Suppose we want to search for files larger than 100MB
    • 1MB = 1024KB, 100MB = 102400KB
    • 1KB = 1024 bytes, 512 bytes = file blocks, 1024 bytes = 2 file blocks, 1KB = 2 file blocks
    • 102400KB = 204800 file blocks
    • Command: find / -size +204800

4. Search according to file type

# 命令格式:find [搜索范围] [-type] [d(目录) 或 f(文件)]
#示例1:搜索根目录下,文件名包含init的所有文件,并且文件类型是目录
find / -name *init* -a -type d 
#示例2:#搜索根目录下,文件名包含init的所有文件,并且文件大于10MB
find / -name *init* -a -size +20480	

Four, Linux commonly used symbols

1.| Pipe symbol

  • The pipe symbol is usually used with the grep command
  • grep is a filtering command, you can filter the search content
  • Example:
    [root@server1 tmp]# cat passwd | grep root
    root:x:0:0:root:/root:/bin/bash
    operator:x:11:0:operator:/root:/sbin/666
    
  • The pipe symbol can pass the output on the left to the command on the right to continue using

2.> Output redirection symbol (overwrite)

  • Redirect the original output content (for example, write it to a specified file)
  • The echo command is equivalent to the print function in other programming languages, output debugging
# 示例1:
echo "Hello World" > /tmp/file1
# 示例2:#之前写入的Hello World会被覆盖
echo "My name is zhangsan" > /tmp/file1	

3. >> Output redirection symbol (addition)

#示例:之前吸入的My name is zhangsan不会被覆盖,追加写入
echo "I'm 18 years old." >> /tmp/file1		

Five, sudo authority management

1. sudo permission management is for commands

2. Permission profile: /ect/sudoers

3. Configuration format: user name operation host = the user who executes the command executes the command

  • Configuration example: root ALL=(ALL) ALL
  • Example 1: zhangsan server1=(ALL) reboot

4. If you want to edit the /etc/sudoers configuration file, you must use the visudo command to open the configuration file, and then you can compile

5. Demonstrate giving zhangsan user restart computer command

#配置信息:zhangsan	ALL=(ALL)	/usr/sbin/reboot
#使用su命令切换到zhangsan用户,
su - zhangsan
#命令重启计算机
sudo reboot

6. Check which sudo commands the user has

sudo -l

7. View the absolute path of the command

which reboot

Six, Linux time command

1. View system time: date
2. Modify system time: date -s “2019-07-23 14:43:00”

Seven, at command

1. Timed task, the command ends after being executed once.
2. Format: at [time to execute the task]
3. Example:

at 14:49
at> echo "hello world" > /tmp/at.txt
ctrl + d 结束输入

Eight, Linux system service commands

1. Check whether the system service command is started

systemctl status [network(网卡服务) 或 atd(定时任务) 或 firewalld(防火墙)]

2. Start the system service command

systemctl start [系统服务]

3. Turn off the system service command

systemctl stop [系统服务]

4. Set the system service to start up

systemctl enable [系统服务]
systemctl enable firewalld	#开机启动防火墙服务

5. Prohibit system service startup

systemctl disable [系统服务]
systemctl disable firewalld	#开机禁止启动防火墙服务

Nine, Linux file compression and decompression

1. Compress and decompress commands

  • Compressed file
    • gzip can only compress files, not directories
    • Format: gzip [file to be compressed]
    • Example: gzip file1
    • When gzip is compressed, the original file will not be retained
  • unzip files
    • Format: gunzip [file to be decompressed]
    • Example: gunzip file1.gz

2. Another compression algorithm bzip2 (just as an understanding)

  • Compressed file
    • Format: bzip2 [File to be compressed]
    • Example: bzip2 file1
  • unzip files
    • Format: bunzip2 [File to be unzipped]
    • Example: bunzip2 file1.bz2
      3. Pack and unpack commands
  • Packaging is to turn the directory into a file without any compression algorithm
  • Packaging commands
    • Format: tar [-option] [file name after packaging] [file to be packaged]
    • Example: tar -cvf dir.tar dir
    • Note: The -f parameter must be placed at the end
    • "-C" package
    • "-V" display process
    • "-F" signature file (the name of the packaged file)
  • Unpack command
    • Format: tar [-Option] [File to be unpacked] [Unpacking path]
    • Example 1: tar -xvf dir.tar ./ ​​#Extract to the current directory
    • Example 2: tar -xvf dir.tar -C /opt/ #Unzip to other directories, you must add -C (note: C is uppercase)
    • "-X" unpack

4. Compress while packaging

tar -zcvf dir.tar.gz dir

5. Decompress while unpacking

tar -zxvf dir.tar.gz -C ./

10. Linux software management


1. The package format of CentOS system is .rpm
2. There are 2 software management methods for linux

  • rpm command
  • yum command
    3. Use of rpm command
  • View
    • Example: rpm -qa | grep'python' #Check whether the system has python software installed
  • installation
    • Example: rpm -ivh /media/Packages/zlib-devel-1.2.7-17.el7.x86_64.rpm
  • Uninstall
    • Example: rpm -e --nodeps zlib-devel-1.2.7-17.el7.x86_64

4. Use of yum command

  • The premise of using the yum command is to ensure that the network is unblocked. It belongs to the online installation of software
  • View
    • Example: yum list | grep'python'
  • installation
    • Example: yum install -y lrzsz
  • Uninstall
    • Example: yum remove -y lrzsz

5. We usually use yum to install software and rpm -e --nodeps to uninstall software

Eleven, crontab timer

1. crontab is a periodic timing task

2. The crond service needs to be turned on before use

  • Check if it is turned on
systemctl status crond
  • If it is not turned on, you need to turn on this service
systemctl start crond

3. Parameters of crontab command

  • -u can specify a certain user to perform this task, usually do not need to add
  • -e Edit timed tasks
  • -l View the current scheduled tasks
  • -r delete timed tasks, note: all timed tasks will be deleted

4. A simple timed task case

* * * * * echo hello > /tmp/crontab.txt

5. Interpretation of timed task time
Insert picture description here
If the time is a time period, you can
use a bar (-) to indicate a continuous period of time;
use (,) to indicate a number of discontinuous times;
use an asterisk (*) to indicate all times;
use division The sign (/) represents the interval time.

6. Timed task practice questions

10 21 * * * 命令			每天的21点10分执行命令
0 5 * * 1 命令			每周一的凌晨5点0分整执行命令
30 4 15,16 * * 命令		每月15号和16号的凌晨4点30分执行命令
*/5 4 * * * 命令			每天凌晨4点,每隔5分钟执行一次命令
0 4 * * 1-5 命令			每周一到周五的凌晨4点0分执行命令
0 0 1,15 * 1 命令		每月1号和15号,每周1的0点0分都会执行命令

7. To delete a timed task, use crontab -e to open the timed task, and then use dd to delete and save

8. Correct the virtual machine time sudo date -s "2019-07-26 14:27:10"

Previous: "Linux Basics Must Know and Know (1)"

Guess you like

Origin blog.csdn.net/qq_35866846/article/details/109253988