This is the 13th day of my participation in the August More Text Challenge. For details, see:August is more challenging

🌈 past review

Thank you for reading, I hope it can help you, if there are flaws in the blog, please leave a message in the comment area or add my private chat in the profile of the home page, thank you for your advice. I’m XiaoLin, a man who writes bugs and raps

  • 🌈 iS MySQL really CRUD? ✨ to see the difference between 2K and 12K (bottom)
  • 🌈 iS MySQL really CRUD? ✨ to see the difference between 2K and 12K (part 1)
  • 💛 : Redis, are you really familiar with it? 💛

One, the introduction

1.1. Linux Introduction

Linux is a free to use and freely spread Unix-like operating system. It is a POSIX and UNIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system. With the development of the Internet, Linux has gained support from software enthusiasts, organizations, and companies around the world. In addition to maintaining a strong momentum in the server operating system, it has made great progress in personal computers and embedded systems. There are many different distributions of Linux, but they all use the Linux kernel. Linux can be installed on a variety of computer hardware devices, such as phones, tablets, routers, and desktop computers.

1.2. Birth of Linux

In the 1980s, the performance of computer hardware continued to improve, and the market of PC continued to expand. At that time, the operating systems available for computers were mainly Unix, DOS and MacOS. Unix is expensive and does not run on PCS. DOS is simple, and the source code is tightly guarded by software manufacturers;

MacOS is an operating system designed specifically for Apple computers. At this time, the computer science field urgently needs a more complete, powerful, cheap and completely open operating system. There were few typical operating systems for teaching, so AndrewS.Tanenbaum, an American professor in the Netherlands, wrote an operating system called MINIX in order to teach his students the inner workings of an operating system. MINIX, while good, is a simple operating system for educational purposes rather than a powerful practical operating system, but the biggest benefit is that it is open source. Computer students all over the world dig into the MINIX source code to get to know the operating system running on their computers. Linus Torvalds, a sophomore at the University of Helsinki in Finland, is one of them. Linus wrote his own Linux operating system (Linux0.01) in 1991, marking the beginning of the Linux era. He used the core of Unix, removed the complex core programs, and adapted it into an x86 system suitable for general computers, and put it on the network for everyone to download. In 1994, the complete core Version1.0 was launched, so that Linux gradually became a functional and stable operating system, and was widely used.

Linux was first developed in 1991 by Linus Torvalds, a student at the University of Helsinki, Finland, and a number of hobbysters who later joined.

1.3. Features of Linux

1.3.1. Free of charge

Linux is a free operating system that can be obtained online or elsewhere and its source code can be modified at will. This is something no other operating system can do. Because of this, countless programmers from all over the world have been involved in modifying and writing Linux. The programmers can change it according to their own interests and inspirations, which allows Linux to absorb the essence of countless programmers and grow.

1.3.2 multi-user and multi-task

Linux supports multiple users, and each user has its own special rights to its own file device, ensuring that each user does not affect each other. Multitasking is now the most important feature of the computer, Linux can make many programs at the same time and independently run, rich network functions, reliable system security, good portability, standard compatibility, excellent speed performance.

1.4, Centos

1.4.1, introduction,

CentOS is one of the Linux distributions. It is compiled from source code released by Red Hat Enterprise Linux under open source regulations. Because from the same source code, so some highly stable servers,) to CentOS instead of commercial Red Hat, Enterprise Linux use. The difference is that CentOS is completely open source.

1.4.2 Differences between centos and READHeat

At present, the Linux operating system is mainly used in production environment. The Linux operating system of mainstream enterprises is still RedHat or CentOS, which comes from the same source code, but CentOS is completely free. Its unique yum commands support online upgrades, allowing you to update your system in real time, unlike RedHat, which has to pay for support services!

1.5. Linux directory structure

  1. Bin (binaries) : stores binary executable files.
  2. Super user binaries (sbin) : stores binary executable files. Only the root user can access them.
  3. Etcetera (etc) : Stores system configuration files.
  4. Unix shared Resources (USR) : used to store shared system resources.
  5. Home: indicates the root directory for storing user files.
  6. Root: directory of the superuser.
  7. Dev (Devices) : stores device files.
  8. Lib (library) : Stores shared libraries and kernel modules needed to run programs in the file system.
  9. MNT (mount) : indicates the installation point where the system administrator installs the temporary file system.
  10. Boot stores the files used for system boot.
  11. Temporary (TMP) Stores temporary files.
  12. Var (variable) is used to store the files that need to be changed at runtime.

2. Common Linux commands

2.1 Format of Linux commands

Command - option parameters such as ls -l /usrCopy the code

2.2, the ls

2.2.1 overview,

The ls (list) command is used to display the list of files and directories

2.2.2 Common Parameters

  1. -l (long) : displays information about files and directories in long format.ls -lAbbreviations isll.
  2. -a (all) : displays all files and directories.
  3. -r: displays the list of files in the specified directory recursively. That is, the list of files in each subdirectory in the branch of the specified directory is displayed.
  4. -h: displays the file size in a user-friendly manner.

Then, the details

File Type File Permission Number of Links Owner Group Size Date time File Name d rwxr-xr-x 8 xiaolin root 4096 Apr 22 09:42 jdk11Copy the code

First message (first) :

  1. D: indicates the current type is directory
  2. – : indicates the file of the current type

Second message (last 9 bits) :

  1. The first three bits: r (read), w (write), x (execute) for the current file creator (user).
  2. The middle three digits represent the operation permission of the group user of the current file creator.
  3. The last three digits represent the permissions of other users of the current file creator on the file.

Third information (1 bit) : indicates the number of file links.

Fourth information: The following link number indicates the author of the current file.

Fifth information: The current file creator is followed by the group in which the current file creator belongs.

Sixth information: After the group, the space occupied by the current file is displayed.

Seventh information: the time when the file was last modified.

Eighth information: file name or directory name.

2.3 File Operation commands

2.3.1, CD

Using the CD command, you can switch the directory. Feel free to switch to the desired directory.

2.3.2 PWD (print Working Directory)

Displays the current working directory

2.3.3, touch

Creating an empty file

2.3.4, mkdir (make directoriy)

To create a directory, it takes a parameter: -p (parents), which means that if the parent directory does not exist, it becomes the parent directory.

2.3.5. Cp (copy)

Cp file name directory: copies files to the specified directory cp -r (recursive) directory name directory: copies the specified directory to the specified directory. -r indicates recursive processing. Files in the specified directory and subdirectories are copied together.Copy the code

2.3.6 mv (move)

Move a file or directory, rename a file or directory

Mv File Name New file name: the file is renamed. Mv File name Directory name: the file is moved. Mv Directory Name Does not exist Directory name: The directory is renamedCopy the code

2.3.7, rm

He has several commonly used parameters

-r: deleting all files in the directory at the same time (recursive) -f: deleting files or directories forcibly (force)Copy the code

The commonly used combination command is rm -rf

2.3.8, rmdir (remove directoriy)

Delete an empty directory. If the directory is not empty, an error message is displayed.

2.3.9 cat (catenate)

Displays text file content, used to display a small amount of content, limited to one screen

2.3.10, head,

Look at the beginning or end of the text

#Look at the first five lines of the a.log file
head  -n  5  a.log 
Copy the code

2.3.11, tail

#Loop reading (fellow, real-time display of file content changes)
tail  -f  b.log 
Copy the code

2.3.12, echo

The output command

#Used to output a sentence to the screen
echo   I love baby

#Type this into the aa.txt file and run it twice to append
echo I Love baby  >>  aa.txt
Copy the code

2.4 Network-related commands

Against 2.4.1, IP addr

View the IP address, which can be simplified as IP a

2.4.2, ping

Test network connectivity

2.5. Tar command

The tar command is equivalent to the Windows good press and is used to decompress or compress files.

#Packaging ordersTar -cvf Package file name source fileCopy the code

He has several parameters:

  1. -c (create) : the parameter instruction for creating a compressed file.
  2. -x (extract) : Unpack the parameters of a compressed file.
  3. -z: whether to use gzip compression,.tar.gz (packaged and compressed with gzip).
  4. -v: displays the file (verbose) during compression.
  5. -f: Uses the file name.

Commonly used combination commands:

  1. Tar file1. TXT file2. TXT: package file1 and file2 into aa.tar.
  2. Tar -zcvf aaa.tar.gz file1. TXT file2. TXT: package file1 and file2 into aa.tar
  3. Tar -zxvf aa.tar.gz: Decompresses the aa.tar.gz file

2.6 systemctl service Command (only for Centos)

It is used to view the status of the service.

#View the running status of a serviceSystemctl status Specifies the service name
#Starting a serviceSystemctl start Specifies the name of the service
#Restarting a serviceSystemctl restart service name
#Stopping a serviceSystemctl stop Service nameCopy the code

2.7 Process-related commands

2.7.1, ps

Queries the processes running on the current console.

#Query all running processes in the system, including background processes. Parameter A is all processes, parameter x includes processes that do not occupy the console, and parameter u displays users.
ps  -aux 

#Query all running processes in the system, including background processes, and can display the parent process number of each process.Ps - ef ps - aux | grep process service nameCopy the code

2.7.2, top

Dynamically display system processes

2.7.3, kill

Kill the process,

#In the preceding command, 1314 is the process number. Generally in executionkillBefore executing this command, use ps or pstree to query the process number of the process to be killed. 
kill  1314

#Force to terminate process 1314, where the -9 parameter means force, in effectkillThe command sends a signal to the process to decide whether to stop running. Some daemons cannot stop running until they receive parameter 9.
kill  -9  1314
Copy the code

2.8. Use the vi/ Vim editor

2.8.1 overview,

Vi/Vim is the most commonly used text editor on Unix/Linux and is very powerful.

2.8.2 Three modes

The VI editor has three modes:

  1. Edit mode (command mode) : All machine key actions are interpreted as editing the entire document. The default is Edit mode.
  2. Input mode: Most key actions are understood as input characters.
  3. Last line mode: In last line mode, enter a number of file management commands.

Patterns can be converted to each other:

  1. Edit mode –> Input mode:

    (1). I: Insert before the character where the cursor is located.

    (2). A: Insert after the character where the cursor is located.

    O: Insert a new line below the line where the cursor is located.

    (4).s: Delete the character where the cursor is located and start the insertion.

    (5). I: Insert at the beginning of the line where the cursor is located. If there is a space at the beginning of the line, insert after the space.

    (6).A: Start the insert at the end of your line where the cursor is.

    O: Insert a new line above the line where the cursor is located.

    (8).s: Delete the line where the cursor is located and start the insertion.

  2. Input mode –> Edit mode: ESC(top left key on keyboard).

  3. Edit mode –> Last line mode: Enter:.

  4. Last line mode :–> Edit Mode: ESC(top left key)(once or more)

2.8.3 Common Commands

  1. I: Insert before the cursor.

  2. I: Start insertion at the current line of the cursor.

  3. A: Insert after the cursor.

  4. A: Insert at the end of the current line of the cursor.

  5. O: Inserts a new line next to the current line of the cursor.

  6. O: Inserts a new line on the line above the current line of the cursor.

  7. :set nu: displays the line number.

  8. :set nonu: Cancel the line number.

  9. Gg: To the first line of the text.

  10. G: To the last line of the text.

  11. :n: To the NTH line of the text.

  12. U: undo to cancel the previous step.

  13. Ctrl + R: redo, return to before undo.

  14. :wq: Save and exit.

  15. Hold shift to save and exit. The function is the same as that of :wq.

  16. :wq! : Forcibly save and exit

  17. :q: Exit without saving.

  18. :q! : Forcibly exits without saving.

  19. Yy: Copy the line where the cursor is located (edit mode).

  20. 2yy Copies 2 lines from the cursor line (edit mode).

  21. P: : Paste command.

  22. U: Undo (edit mode).

  23. 1,$d: delete all (last line mode).

2.8.4 Move the cursor and flip the screen

2.8.4.1 Character by character movement

  1. H: Move left.
  2. L: Move right.
  3. J: Move down.
  4. K: Move up.

2.8.4.2 Intra-line jump and inter-line jump

  1. 0: jumps to the beginning of the line.
  2. $: jumps to the end of the line.
  3. G: : Skip to the last line of the line (you need to enter the keyboard G in edit mode).
  4. Gg: Jumps to the first line (requires two keystrokes gg in edit mode).
  5. CTRL + F: Scroll down a page.
  6. CTRL + B: Turn up a page.

2.8.4 Find and Replace

  1. / Conditions to match: search from front to back.
/s
Copy the code
  1. ? Search conditions: Search from the back to the front.
? sCopy the code
  1. N: the next matched string (edit mode).
  2. N: last matched string (edit mode).
  3. G: global substitution.
  4. I: Ignores case

2.9 Software commands

2.9.1 RPM command

2.9.1.1 Overview of RPM

RPM stands for RedHat Package Manager, a format whose name bears the RedHat logo but whose original design was open, The distributed versions of Linux, including RedHat, CentOS, and SUSE, are now adopted, which can be regarded as the recognized industry standard. RPM files are easiest to install on Linux systems,

2.9.1.2 RPM command

Common parameters of the RPM command:

  1. I (install) : installs applications.
  2. E (erase) : uninstalls the application.
  3. Verbose hash (VH) : displays the installation progress.
  4. U (Update) : upgrades the software package.
  5. Query All (QA) : Displays all installed software packages.
#The progress is displayed. Install gCC-C ++-4.4.7-3.el6.x86_64.rpmRMP - the ivh GCC - c + + - 4.4.7-3. El6. X86_64. RPMCopy the code

2.9.2 the yum command

Yum (Yellow dog Updater, Modified) is a Shell front-end package manager found in Fedora and RedHat, as well as SUSE and CentOS. Based on RPM package management, it can automatically download and install RPM packages from specified servers, automatically deal with dependency relationships, and install all dependent software packages at one time, without tedious downloading and installation. You must connect to an external network to use the YUM command

2.10 User and Group-related commands

A user is defined as a user that has the ability to access a resource or service. A user group (a container that stores a list of users). A user group also has the permission to access a resource

  1. Whoami: displays the current user.
  2. Exit: exits the user.
  3. Groupadd: adds a group.
  4. Groupdel: deletes a group.
  5. Useradd: adds a user with one parameter-gIf you do not specify a group name when you create a user, the system automatically creates a group name that is the same as the user name.
  6. Passwd User name: sets the user password.
  7. Su User name: indicates the user to switch to.

2.11 Permission related commands

Permission is defined as the ability of a specific person to access a resource or service. Linux files have three typical permissions: R read, W write, and X execute. There are nine columns of permission bits following the file type in the long-format output, which are actually user-specific. R =4, w=2, x=1.

R (read) : indicates that the directory can be read. If the r permission is not granted for a directory, the contents of the directory cannot be viewed through ls. W (write) : The table is writable. For a directory, if the w permission is not granted, it means that new files cannot be created in the directory. X (Excute) : The table means writable, means executable, and in the case of a directory, not having X permissions means that the directory cannot be accessed via CD.

2.12. Search for related commands

2.12.3. Document related

  1. Whereis Command name: search the path where the command is located and the location of the help document.
whereis  ls
Copy the code

  1. Which: The path and alias of the search command
which ls
Copy the code

  1. Find Search scope Search criteria: Find searches the system for file names that match the search criteria. Wildcard characters are used to match the file names.
#Case insensitive
find /root -iname install.log	
Copy the code

2.12.4. String search

The basic format is grep [Option] String file name.

The options are:

  1. -i: ignores case.
  2. -v: excludes the specified string.

2.12.5 Differences between the find and grep Commands

The find command is used to search for the file name that meets the requirements.

Grep command: search for a string that meets the requirements in the file.

2.13 firewall

Centos7 firewall server is named Firewalld, and its related commands are as follows:

  1. Firewall configuration command: firewall-cmd.

  2. Fireweall -cmd –help.

  3. Run the firewall-cmd –state command to check the firewall status.

  4. Run the firewall-cmd –zone=public –list-ports command to view all open ports.

  5. To enable the port, run the firewall-cmd –zone=public –add-port= port number/TCP –permanent (the –permanent parameter is valid forever, otherwise it will be invalid after the restart).

  6. Update the firewall rule to firewall-cmd –reload.

  7. To delete a port, run the firewall-cmd –zone=public –remove-port= port number/TCP –permanent command.