What permissions does a user have on a file or directory?
Four types: Read, write, execute, no permissions
Second, how to express these four kinds of authority?
If expressed in decimal digits: 4, 2, 1, 0, respectively: R, W, x 、-。 Personally, when using the chmod command to change file or directory permissions, the digital notation is clearly more concise than the character notation
Does the four permissions have the same meaning for files and directories?
This is not the case, as follows:
---------------------------------------------------------------------------
Normal file directory
R: The user has permission to read the contents of the file the user has permission to list the files in it
W: User has permission to modify the contents of the file the user has permission to create and delete files in it
X: User has permission to execute the file the user has permission to enter the directory, copy the file
----------------------------------------------------------------------------
To the directory of these individual permissions of the operation, I have one by one trials, detailed results affixed to the end of the text, the picture is no longer posted. What you need to be reminded of:
1, have a certain permission, does not mean that it is certain to be able to do the corresponding operation of the file or directory.
2, ordinary files have R, W, x permissions or a combination of their permissions, for the file content, and the operation of the file itself is independent. If you want to delete, move, and so on the file itself, you need the permissions of its upper directory, as described below.
Four, why should you set the permissions of three groups of users at the same time?
This is because the permissions for files or directories in Linux are associated with user management. We set the permissions of the file, in addition to setting the owner's permissions, but also to set the owner of the same group of users, as well as other user permissions. For Linux user management, please search for the relevant information yourself.
Five, why are many files or directories permissions are a combination of permissions?
As mentioned earlier, having a certain permission does not necessarily mean that you can complete the operation, one of the reasons is that a single permission can not guarantee that we complete the corresponding operation, so when setting file or directory permissions, usually use a combination of permissions, which is particularly important for the permissions of the directory. For example, in the sense that if the directory has W permissions, we can create new, delete files in it, but from the actual operation results, these operations can not be completed, only when the directory has the X permission to do the above operation. -WX permissions, that is a combination of permissions, for the directory, the user can create, delete files, and then the common r-x combination: For the directory, the user can list the contents of the directory, copy the files. Can say, do not have the X permission of the match, the directory of W permission is an empty word, no X permission of the match, can not do anything to the contents of the directory, as for the operation of the directory itself, the permissions of its upper directory is determined. Can you understand? If you can't get into the directory, what about the files in the directory?!
What can we do with a file or subdirectory when the directory has a permission combination rw-, R-x,-wx? You can guess first, then try it out and see if your guesses are correct. RWX permissions are not considered, basically full permissions, of course, except for special permissions.
Vi. What are the effects of permissions on files or directories?
Having a permission does not necessarily mean that you will be able to do it, not just because a combination of permissions is required, but sometimes this happens: we set the right combination of the file or directory correctly, but still cannot manipulate it. This is because the ability to perform various operations on a file or directory depends not only on the permissions of the file itself, but also on the permissions of its upper directory. This is already mentioned in Part III and V of this article. It's very important to remember it!
Take a look at the operation of the file, including two parts: the operation of the file itself, and the operation of the contents of the file.
Operations on the file itself are generally moved, copied, deleted, renamed, and all of these operations are determined by the permissions of their upper-level directories. Can you understand? File is a directory of files, we know that the Linux directory also as a file, then everything in the directory can be regarded as the content of the file, so the permissions of the directory determines the directory of the operation of the file, which mainly refers to the operation of the file itself, the operation of the contents of the file, but also need the file's own permissions.
User Lqs has a directory in the home directory 000, which has a file a.txt. Home directory Lqs has set permissions 705, directory 000 permission is set to 703, where the A.txt file permission is set to 700. Other user normal has successfully deleted the file a.txt, although the file's permissions are only 700! This is because the deletion of files and other operations are determined by the permissions of the upper directory, and the file's upper directory 000 has a permission of 703, which gives other users to add, delete the file permissions.
Therefore, we conclude that it is possible to move, delete, rename, and so on the file itself in the directory, depending on the permissions of its upper directory. The file here refers not only to ordinary files, but also to directory files, which are subdirectories of the directory.
The operation of the contents of a file generally refers to modifying the contents of the file. Operation of the contents of the file, first of all its directory to have X permission, and then file to have W permission.
The operation of subdirectories in the directory is consistent with the operation of the files in the directory, but the corresponding permissions are consistent with the permissions of the directory operations mentioned earlier. Not listed here. Remember, to use more chmod commands, you will naturally know these things.
Vii. Special Privileges
Linux has some special permissions, such as S, which require 4-bit decimal numbers to represent them. There is no discussion here, and it is interesting to know for yourself.
Appendix:
First, how does the permission character representation become a digital representation?
When you use the LS–L command to display the long format of a file's properties, the first field is used to represent the type and permissions of the file, and the most common value for this field is-rwxr-xr-x. A total of 10 characters, the first bit represents the file type, the following nine bits represents the file permissions, the 9 characters can be divided into 3 groups, respectively, the permissions of the owner of the file, belong to the main group of users, and other user permissions.
Rwxr-xr-x means that the owner of the file has read, write, execute all permissions, belong to the main group of users with readable permissions, other users have the ability to read, in decimal numbers, that is, 755.
So, how did 755 come about?
To arrive at this decimal number, you need to convert the rwxr-xr-x to binary first. If they are represented by a binary number, there is a permission of 1, not 0, then the binary representation of RWXR-XR-X is 111 101 101.
Then 111 101 101 of the three sets of binary numbers are converted to decimal. Conversion algorithm do you remember? From right to left, the numbers on each of you are multiplied by 2 of the n-th (the value of n is from 0). As shown below:
First group: 1x20 + 1x21 +1x22 = 7
Second group: 1x20 + 0x21 +1x22 = 5
Group Three: 1x20 + 0x21 +1x22 = 5
Three sets of numbers together, that is, 755.
In fact, not every time each character into a binary, and then converted to a decimal, not so troublesome. Because we can figure out: The readable permission is represented by a decimal number as 4, the writable permission is represented as 2, the executable permission is represented as 1, and no permission is represented as 0, so remember that they don't have to go around every time.
Let's take a look at the readable permission r--, whose binary representation is 100, converts it to decimal: 0x20 + 0x21 +1x22 = 4
Then look at the writable permission-w-, whose binary representation is 010, converts it to decimal: 0x20 + 1x21 +0x22 = 2
Finally, the executable permission--x, its binary representation is 001, convert it to decimal: 1x20 + 0x21 +0x22 = 1
II. the specific operational test results of each authority are as follows:
Readable permissions to the directory: You can list the files in the directory, cannot rename, copy, move, delete the files therein, not to enter the directory
Writable permissions of the directory: cannot list files in the directory, cannot rename, copy, move, delete files in it, do not enter the directory
Executable permissions of the directory: cannot list the files in the directory, can not rename, move, delete the files therein, copy the files, you can enter the directory.
Article Source:http://www.examda.com/linux/fudao/20100707/094403862-1.html
Linux File Permissions Learning Summary