Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

5.2 File permissions and attribution


May 23, 2021 That's what Linux should learn



Although everything is a file in a Linux system, the types of each file are different, so the Linux system uses different characters to distinguish between them, as shown below.

-: Normal files.

d: Directory file.

l: Link file.

b: Block device files.

c: Character device file.

p: Pipeline file.

In a Linux system, each file has its own owner and all groups, and provides permissions for the file's owner, all groups, and others to have readable (r), writeable (w), executable (x), and so on. F or a typical file, permissions are easier to understand: Readable means that the actual contents of the file can be read, Writeable means that the actual contents of the file can be edited, added, modified, and deleted, and Executable means that a script program can be run. H owever, it is not so easy for directory files to understand their permission settings. Many senior Linux users don't really understand.

Mr. Liu Wei is here to explain in detail the permission settings of the directory files. For directory files, Readable means being able to read a list of files in the directory, Writeable means being able to add, delete, and rename files within a directory, and Executable means being able to enter the directory.

The read, write, and execute permissions of a file can be shorted as rwx, or they can be represented by the numbers 4, 2, and 1, respectively, and there is no association between the file owner, the group, and other user permissions, as shown in Table 5-5.

Table 5-5 The characters and numbers of file permissions are represented

5.2 File permissions and attribution

The numeric method of file permissions represents a calculation based on the permissions represented by characters (rwx), with the aim of simplifying the display of permissions. F or example, if a file has permissions of 7, it represents readable, writeable, executable (4 plus 2 plus 1), and if the permission is 6, it represents readable, writeable (4 plus 2). L et's look at an example like this. T here is now a file whose owner has readable, writeable, executable permissions, whose group belongs to a file that has readable, writeable permissions, and others who have readable permissions. W ell, the permission of this file is rwxrw-r--, the numeric method means 764. However, we must not add these three numbers, calculate the results of 7 plus 6 plus 4 plus 17, this is the primary school math addition and subtract, not the Linux system's permission number notation, there is no interoperability between the three.

The file permissions for Linux systems are quite complex, but they are widely used, and it is recommended that you thoroughly understand them before you learn about the next section. N ow let's practice. Readers are invited to calculate the character notation for numeric notation 764, 642, 153, 731, and then convert rwxrw-r--、rw-w-wx, rw-r-r--into numeric notation.

Let's use the knowledge described above to analyze the file information shown in Figure 5-1.

5.2 File permissions and attribution

Figure 5-1 shows the file property information viewed by the ls command

In Figure 5-1, it contains information such as the type of file, access rights, owner (owner), group (group), occupied disk size, modification time, file name, and so on. Through analysis, it can be found that the file type is ordinary file, the owner permission is readable, writeable (rw-), belongs to the group permission is readable (r---), in addition to others only readable permission (r--), the disk size of the file is 34298 bytes, the most recent modification time is April 2 at 23 a.m., the name of the file is install.log.