Linux uses binary to set file permissions

1. Popularize binary knowledge

Binary data is a number represented by two digits, 0 and 1. Its base is 2, and the carry rule is "every two into one".

Binary is the algorithm used on the world's first computer. The oldest computer has light bulbs.

When computing, such as to express "one", the first light bulb will light up. To express "two", the first light bulb goes out and the second light bulb comes on.

Second, the expression algorithm

111 

The first 1 is 2² (2 to the power), which is 4 

The second 1 is 2¹ (2 to the power), which is 2

The third 1 is 2º (2 to the zeroth power), which is 1

So adding up gives the following result:

000=0
001=1
010=2
011=3
100=4
101=5
(4+0+1=5)
110=6
(4+2+0=6)
111=7
(4+2+1=7)

3. Convert Linux permissions to binary

-r-xr-xr--
101 101 100
554
-rw--w---x
110 010 001
621
-rwxrwxr--
111 111 100
774
-r---w---x
100 010 001
421

To summarize the rules: r means 4 , w means 2 , x means 1

Fourth, set the permissions of the file through the command

touch abc.txt                 //Create an abc.txt file

chmod 621 abc.txt // Set 621 permission to the abc.txt file   




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325392065&siteId=291194637