chmod

File/directory permission setting command: chmod, used to change the access permission of a file or directory.

There are two usages of this command: 

1. Use the text setting method containing letters and operator expressions: the syntax format is: chmod [who] [opt] [mode] file/directory name 

2. The number setting rule is simpler: chmod [mode] filename 

 

1. Letter and operator expression setting method:

where who stands for object and is one or a combination of the following letters: ugoa

u: Indicates the owner of the file g: Indicates users in the same group o: Indicates other users a: Indicates all users 

opt represents an operation, which can be: +: add a permission -: cancel a permission =: grant a given permission and cancel the original permission 

And mode represents permissions: r: readable w: writable x: executable 

For example: increase the read and write permissions to the file a.txt for the same group of users: chmod g+rw a.txt 

 

2. Use digital setting method: chmod [mode] file name 

The key is the value of mode. We regard rwx as a binary number. If there is, it will be represented by 1, and if not, it will be represented by 0. Then rwx rx r- - can be expressed as: 111 101 100 - can be expressed as: 111 101 100 

Then convert every three digits of it into a decimal number, which is 754. 

 

For example, we want the permissions of the a.txt file to be: 

Can other users in the same group be readable or writable or executable 

Then, we first get the permission string according to the above table: rw-rw-r--, then the conversion into binary number is 110 110 100, and then every three digits are converted into a decimal number, which becomes a decimal number, and 664 is obtained, So we execute the command: chmod 664 a.txt

Guess you like

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