What does linux shell mean?

青灯夜游
Release: 2022-11-11 11:18:57
Original
1977 people have browsed it

In Linux, shell refers to "shell", which is the "command line interpreter" that exists on the operating system. It refers to a user-oriented command interface, which is expressed in a form that can be entered by the user. interface, this interface can also feed back running information. The functions of the shell: 1. Translate the user's commands to the kernel for processing; 2. Translate the core (kernel) processing results to the user.

What does linux shell mean?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

The shell program of Linux is called shell (command line interpreter), which refers to a user-oriented command interface. The form is an interface that can be entered by the user. This interface can also feed back running information

The function of shell is:

  • Translate the command to kernel

  • Translate the kernl processing result to the user

Generally, the shell we use is bash.

When interpreting a command, bash will not directly participate in the interpretation, but will create a new process to interpret the command. Bash only needs to wait for the result, which ensures the security of the bash process.

1. Shell

1. Reason

When using Linux, we all Compared with windows, linux does not have a graphical interface and uses the command line for operations. However, the command line method is not a direct operation of the computer. We know that the bottom layer of the computer is actually composed of

0 and 1

. The transmission of each command will eventually be converted into 0,1 signals and transmitted to the computer to allow the computer to run the corresponding instructions. But if everyone uses computers in this way, it will undoubtedly be very difficult.

2. FunctionThe Linux operating system serves as a

core (kernel)

, and users cannot directly Its operation. Instead, it communicates with the computer through shell. The English meaning of "shell" is "shell", which is the "command line interpreter" that exists on the operating system and is used to translate user commands Processed by the core (kernel), the core (kernel) then translates the processing results to the userThe shell can actually be regarded as a

translator## between the user and the operating system #, the language barrier between the user and the operating system

cannot communicate directly , but the conversation is conducted through translation through the shell

3. Windows and Linux shells

(1)windows

When using windows, the user cannot directly operate the kernel of windows, but forms a shell by clicking on the shell Graphical interface

to perform related operations

(2) linux

In linux, the shell isParse our instructions

, pass the parsing instructions to the linux kernel, feedback the results and then

run the results through the kernel, and parse the results to the user through the shell

4. Existential significance

(1) Facilitate communication between the user and the operating system

Through the shell, users can use the operating system in a more simple

way, and the learning cost will also be greatly reduced.

(2) Protect the operating system

Another purpose of shell is to protect the operating system. By intercepting illegal or invalid user instructions

,

avoiding the operating system from performing useless or harmful operations. For example, if we enter a string of garbled characters under Linux, the shell will intercept the command and return

What does linux shell mean?

5. Running mode

When the shell executes a command, it will execute the user's instructions by

forking a child process, and the

shell itself will generally not execute the corresponding instructions . You can think of shell

itself as a

president of a translation dispatch company. When users have translation needs, they make requests to shell, and shell, as the president of a dispatch company, Generally, we will not provide door-to-door services in person, but will send other translators under our command to provide services in order to cope with the numerous and complex needs. These expatriate translators are a child process.

2. Linux permissions

##1. The concept of Linux permissions

Permissions are the permissions for users in the operating system Constraints

(1) User classification

Under Linux, users are divided into two types. One is

superuser, which is root. The other is ordinary users.

1. Super user (root)

There is only one root user. At the same time, the root user has the highest permissions on the operating system.

It can be considered that the root user in the operating system is like the emperor of an ancient country and is not bound by any legal provisions. Under the root user,

executing any command will not be restricted by permissions. You canaccess other ordinary users' files and modify and delete them. You can execute delete the root directory of the operating system, database and other operations that will cause serious damage to the operating system or even crash

Therefore, the password of the root account must be set to a complex one and kept well.

The command prompt of root user is“#”

##2. Ordinary user

Ordinary users can have multiple

. Ordinary users will be subject to permission constraints. These permission constraints come from the system and root users.

The command prompt for ordinary users

is“$”

## (2) User switching

Under Linux, you can use the "su" command to switch users

Here, you need to enter the password of the account you want to log in to. . Therefore, try to set the password for each account to be different What does linux shell mean?

To exit the account, enter

exit

or use the shortcut key

"ctrl d"that is Can

Note:What does linux shell mean?When using "su" as a normal user, you need to enter the password of the corresponding user

. However,

"su" under the root user, there is no need to enter the corresponding user password

What does linux shell mean?

(3) Do not switch users to perform correspondence Command

If we are an ordinary user

, but at this time we need to

execute an instruction that requires root permissions, and we If you don't want to switch users to execute , you can use the "sudo" command at this time. This command can temporarily elevate the permissions of ordinary users. Note: When entering the password, enter the password of this user, not the password of the root user

But at this time we will have the following error:

This is because What does linux shell mean?the ordinary user is not a trusted user of root

, and the ordinary user does not exist in the corresponding file of root, resulting in the inability to perform "sudo" Command

2.linux permission management

In Linux, permissions are determined by "人"

and

" Composed of "thing attributes". refers to the user who performs the operation, Thing attribute refers to the attribute of the file (1) Classification of file visitors (people)

In Linux, file visitors are divided into three categories: Owner (onwer) ,

group

,other. Unlike root users and ordinary users, who are specific people, the three types of file visitors are a relatively abstract concept, which can be regarded as a role. That is The identities of other users under this file. For example, an ordinary user may appear to be the owner and group of files in his own directory, but may appear to other users' files to be other people1.Group to which they belong The reason for existence

Some people may be confused. The owner of the file is easy to understand with other people. The owner is the creator of the file, and

other is except the creator. If you are an external user

, what is the significance of the group to which the file belongs?

Suppose now we have Team A and Team B developing products on the same Linux machine. At this time, members of Team A have implemented a module, and the team leader wants to view the content of the module. . If owner and other exist in Linux, because owner is ourselves, then when the leader wants to view the code, we need to release other's permissions. But another team is also regarded as other by this document. Letting go of other means that not only the leader can see it, but also the other team can see your code, which can easily cause code leakage. To avoid this situation, you need to belong to a group. We only need to add the leader to the group to which the file belongs and release the permissions of the group, so that we can open the code to the leader without opening other permissions

(2) Thing attributes

What does linux shell mean?

Now we have the above test.c file, you can see , there is a long list of attributes before the file name. Before, we knew at most "Oct 25 16:43" is the last modified time , 100 is the file in bytes. File disk usage . But we don’t know the previous attributes.

1. File visitors

What does linux shell mean?

We also mentioned the classification of file visitors above. In fact, in the picture above The first root represents the owner , The second root refers to the group it belongs to . Other is not displayed, because users other than these two users belong to other, and there is no need to display

2. File type

What does linux shell mean?

We all know that In Linux, the suffix of a file is meaningless . Because linux does not distinguish file types by file suffixes. But that doesn't mean there are no file types in Linux. Linux file types are distinguished by the first character in the first column of the attribute column displayed by "ll" . As you can see in the picture above, the first characters in test and test.c are the characters "d" and "-" respectively. These two characters are actually the file type.

1) Common file types in Linux

-: Ordinary files

mainly include source code, library files, Executable programs, document compression packages, etc.

d: Directory files

c: Character device files

Mainly hardware , such as keyboard, monitor, etc.

b: Block device file

For example, disk

l: Link file

Taking windows as an example, the shortcut on the desktop is actually a link file. The shortcut links to the startup program of the corresponding software. Under linux, we execute the "ln -s a.out test" command:

What does linux shell mean?

At this time, a # is created for the a.out file ##Link file test, and the beginning of the file is actually "l", which represents Link file

If we want to execute a.out file , you can use test:

What does linux shell mean?

p: Pipe file

Pipe file involves

inter-process communication , I won’t go into details here, now you just need to know that such a file exists

3. File permissions

1What does linux shell mean?

You can see So here, except for the first character which is the file type, there are 9 characters left. At the same time, we know that

file visitors are divided into three categories , and among these 9 characters, every three characters of represent a type of visitor's access rights .

(1) File permission classification

File permissions are divided into three categories, namely

"r", "w", "x" .

"r" stands for read, that is, reads the file. "w" represents writing , that is, modifying the content of the file. '"x" represents execution, that is, executes the corresponding file

The visitor permissions of each file are composed of these three permissions. Sort in the manner of "rwx". If the corresponding permission is "-", that is, you do not have the permission

1What does linux shell mean?

As shown in the above picture, the permission "rwx -xr r-x" , means that the owner has read, write, and execute permissions; the group to which belongs has read and write permissions, but no execution permissions;The visitor has read and execute permissions, but no write permissions Permission. The spaces are added here just to facilitate the distinction. There will be no spaces in the actual display

(2) Permission modification

1. Modify

one by one

Permissions in Linux also support modification. When modifying, use the "chomd" command. For example, if we want to change the executor permissions in the picture below to "-wx", we can execute "chomd u-r test":

1What does linux shell mean?

This In this form, "u" represents the owner , "-" represents to remove the corresponding permission . And "g" represents the group to which belongs, and "o" represents other people . If you want to modify the permissions of other visitors, just modify "u" accordingly. If you want toadd some permission, you canchange "-" to "".

Of course, when adding or deleting permissions, you can also use the form of multiple visitors and multiple permissions, such as "chmod u-rwx,g-rwx test":

1What does linux shell mean?

If you want to modify the permissions of all visitors , you can also change "u, g, o" to "a ” Bring the corresponding permissions, which will not be demonstrated here.

2. Modify the file owner and group

To modify the file owner, you need to have the corresponding permissions, otherwise you need to use "sudo" Elevate rights. The command to modify the file owner is "chown corresponding user file name":

1What does linux shell mean?

If you want to modify the group it belongs to , use "chgrp" Command, The usage method is the same as "chown" , it will not be demonstrated here

If you want to modify the owner and group at the same time , just use the "chown username:username file name" command, the usage method is the same:

1What does linux shell mean?

The root user is used here , no need for sudo to use, ordinary users need sudo.

For other, there is no need to modify , because users other than the owner and the group they belong to are other

3. Permissions are modified at the same time

We have said that in computers, all commands are transmitted in the form of 0,1 signals.

Permissions existwith and without two states, which are also composed of 0 and 1. "rwx" can be seen as "111", "---" can be seen as "000". And if these binary are converted to octal, they are "7" and "0". Therefore, the octal range of permissions can be viewed as "[0, 7]". In octal, "r" represents 4, "w" represents 2, "x" represents 1

Thus, when modifying permissions, in addition to using "u-" to modify the permissions, we can alsomodify in octal form. That is"chmod the octal number combination of three visitors file name". For example, "chmod 777 test"

1What does linux shell mean?

This modification method is better than the first method to modify the permissions of multiple visitors one by one. To be convenient

Note: If you do not write the whole number in this way, such as "7", "35", the system will work from back to front. That is, modify it from the direction of other->group->owner, because other permissions default to 0 at this time and will not be displayed. As shown below:

1What does linux shell mean?

3. Permission mask

In fact, the starting permission of the new directory is 777, and the new folder## The starting authority of # is 666. But what we actually see is not like this. The reason is that creating files or directories will be affected by umask (permission mask).

(1) The role of permission mask

umask value, that is, the permission

that exists in the permission mask, the system will automatically configure it. When generating a file or directory, remove the permissions in the permission mask.

(2) View umask

To view the umask value, directly enter the

"umask" command:

1What does linux shell mean?

We don’t need to worry about the first 0 here. What follows the

first 0 is the permission that each visitor needs to remove. That is, by default in the system, the owner of each newly created file or directory does not need to remove permission , and the group to which belongs needs to remove 2, that is, write permission;Others need to remove 2, that is, write permission

What does linux shell mean?

Remove 022 from the starting permission of the file 666, the beginning of the directory Remove 022 from permission 777 to get the permission in the picture above.

It should be noted that the umask values ​​of ordinary users and root users are different. The umask value of

ordinary user is 002, and root user is 022

(3) Modification The umask value

Although the umask value can be generated by the system by default, it can also be modified manually.

The modification method is

"umask 0 corresponding permissions". For example, "umask 0444":

2What does linux shell mean?

You can see that after modifying the umask value, the corresponding permissions in the default permissions of the newly created file are removed.

Note:

The umask value does not use the initial permission to reduce the permission value, but removes the corresponding permission . For example, the initial permission of the file is 666. At this time, we change the umask value to 0111. If you use subtraction, it will become 555, which is "r-xr-xr-x". But in fact it should beremove the "x" permission corresponding to 1, that is, it is still the "666" permission, that is"rw-rw-rw-":

2What does linux shell mean?

Some people may wonder why the starting permissions of the directory are 777, while the starting permissions of the files are 666. The reason is that to

enter a directory, you need execution permissions, that is, "x" permissions:

2What does linux shell mean?

If you are in the

root user# If the above operation is performed under ##, can enter the directory without "x" permission, because the root user is not restricted by permissionsRelated recommendations: "

Linux video tutorial

The above is the detailed content of What does linux shell mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!