[Linux] shell and its operating principle

1. What is a shell

shell : the shell of the operating system kernel

Generally speaking, computer hardware is composed of arithmetic units, controllers, memory, input/output devices and other hardware, and the thing that allows various hardware devices to perform their duties and work together is the operating system. (For details, see the role of the blog operating system in hardware )

Strictly speaking, Linux is an operating system, we call it "kernel", but we ordinary users cannot use the kernel directly, because the kernel directly manages the hardware, and the system kernel is too important for the computer. If Direct use of the kernel may modify some parameters in the kernel, causing problems in computer use, and direct use will increase the difficulty of operating and learning the computer operating system.

Therefore, general users manage computers through programs or services developed based on the system call interface (the blog in the link above has a brief introduction), that is, through the kernel's "shell" program, the so-called shell, to communicate with the kernel. (Windows system is also a similar operation)

  • The shell here is a general term, and the shells corresponding to different operating system kernels are different.
    insert image description here

From a technical point of view, the simplest definition of a shell is: a command line interpreter
uses the command line shown in the figure below to execute a program.
insert image description here

2. The function of the shell

The main functions of the shell :

  • Translate user commands to the kernel for processing
  • At the same time, translate the core processing results to the user
  • protect the operating system

Compared with windows GUI (the graphical interface under windows), we operate windows not directly operate the windows kernel, but through the graphic interface, click to complete our operation (for example, to enter the D drive operation, we usually double-click the D drive letter , or run an application).

The shell has the same effect on Linux, mainly to parse our instructions and send them to the Linux kernel. Feedback results are generated through the kernel and parsed to the user through the shell.

insert image description here
Many mainstream Linux systems, including the Red Hat system, now use the bash interpreter as the default shell (terminal). The cloud server centos I use uses the bash interpreter, which can be viewed here.

[root@VM-16-5-centos ~]# ls /usr/bin/bash -al
-rwxr-xr-x 1 root root 964536 Apr  1  2020 /usr/bin/bash   //命令行解释器,shell

The mainstream Linux system chooses the Bash interpreter as the command line terminal mainly has the following four advantages, which you can slowly experience in your study and work. (Through the use of this blog, you can also see some common Linux instructions )

  1. Use the up and down arrow keys to call up the Linux commands that have been executed in the past;
  2. Commands or parameters can be completed with the Tab key only by entering the first few digits;
  3. Has a powerful batch script;
  4. Has a practical environment variable function;

3. Perceptual understanding of shell

Character brief introduction:

  • Me: I am a rich second generation who is not good at words, but has money and power. In my village, everyone wants to give me some face.
  • Old man: My dad, the richest man in the village is the head of the village, rich and powerful.
  • Ruhua: My crush, but she hates me, and what she likes is the fool who lives next door to her.
  • Two fools: Ruhua's boyfriend, and Ruhua are getting married soon, but no one knows without Zhang Luo.
  • Wang Po: The famous matchmaker in our village, rumor has it that matchmaking has never failed.

insert image description here
Story:
I like programming since I was a child, but I am introverted and have never been in a relationship. I blush every time I talk to girls, and I am shy when I go out without a hat. After graduating from university, I found a very good job with my own efforts. Work.

After graduating from university and returning home, the old man said to me: "You have found a good job, and you have reached the age, should you find a wife?", I thought of Ruhua in our village. I go to a school, and I can't help but like it every time I see it. So I told the old man, and the old man said after hearing this: "We need to talk to others about this matter, find a matchmaker to propose a marriage, it just so happens that the queen woman in the same village does this, and she is very capable and has never missed a shot." So Wang Po was called, and after saying this, Wang Po immediately set off to Ruhua's house.

When I arrived at Ruhua's house, I told Ruhua all this and so on, and said that my family has money, power, and a good job. . . . Ruhua listened to Wang Po's narration, and thought of me, the one who was taciturn since she was a child, who often pinched her nose and hands to her mouth when she was in elementary school, didn't have a good impression of me, so she told Wang Po that I was incompatible and she didn't like me , Wang Po persuaded me a few more words, seeing that it was useless, she went back home and came to my house, and told me that Ruhua thinks you are very good, but you are not suitable for the two, or you can change one. As soon as I heard it, I sat there motionless. The old man knew what I meant when he saw me like this, so he asked Wang Po to go in order again, and he must succeed.

When Wang Po heard that there was no other way, she went to Ruhua's house again. When you arrived at her house, you saw Ruhua's parents sitting with the parents of the second-blind man next door. Marriage, you look at the situation, you know that the matchmaker can't go on, so go to your own home.

When I got home, Wang Po began to think about this matter. Because of my family's status in the village, she didn't dare to offend her, and Ru Hua started to get married. This was destined to be difficult to solve. It is said that the status of the media is about to be lost, what should we do?

In the end, Wang Po came up with an unwise method, recruiting interns and letting the interns go as matchmakers. If one fails, just two, and if two fail, replace the other. If there are too many, it proves that this matter cannot be solved. I will be able to understand the problem, and Wang Po's reputation will be preserved. After all, it is the intern who is the matchmaker, not her Wang Po.

it's here:

Me: User
Matchmaker: shell
Wangpo: bash—a type of shell
Ruhua: operating system kernel

  • An intern is a process, there are multiple interns means there are multiple sub-processes, and the process completes the user's instructions (understand)

insert image description here
So the operating principle of the shell can be summarized in one sentence:

The shell is the software shell of the operating system kernel. The user sends an instruction to the operating system, the shell accepts the instruction, and passes it to the operating system. After the operating system processes it, the shell accepts and passes the result to the user.

4. Why not install a graphical interface

Some graphical interfaces in the Linux system are really easy to use, which greatly reduces the probability of operation and maintenance personnel making mistakes.

However, many graphical interfaces actually call scripts to complete corresponding tasks, which are often designed only to complete certain tasks, lacking the original flexibility and controllability of Linux commands.

Furthermore, the graphical interface will consume more system resources than the Linux command line interpreter, so experienced operation and maintenance personnel will not even install a graphical interface for the Linux system, and directly use the command line mode to start the operation and maintenance work. connected remotely,

Doing so is much more efficient.

Guess you like

Origin blog.csdn.net/m0_52094687/article/details/128415261