When you use the LL or ls-l instructions, the first column displays the permissions of the files in the directory
For example:
-rw-r-r-
The horizontal line represents an empty license. R is for read only, W for write, and X for executable. Note that there are 10 locations. The first character specifies the file type. In the usual sense, a directory is also a file. If the first character is a horizontal line, it indicates a directory that is not a directory.
After determining the access rights of a file, the user can use the chmod command provided by the Linux system to reset different access rights. You can also use the Chown command to change the owner of a file or directory. Use the CHGRP command to change the user group for a file or directory. These commands are described separately below.
chmod command
chmod [who] [+ | | =] [mode] File name
The meaning of the options in the command is: The action object who is either one of the following letters or a combination of them:
U means "user", which is the owner of the file or directory.
G means "same group user", that is, all users who have the same group ID as the file owner.
O means "other (others) users".
A means "all users". It is the system default.
The operation symbols can be:
+ Add a permission.
-Cancels a permission.
= gives the given permission and cancels all other permissions, if any.
Setting the permissions represented by mode can be any combination of the following letters:
R Readable, digital code "4"
W Writable, Number code "2"
X is executable and the number code is "1".
-no permission, the number code is "0".
x append the x attribute only if the destination file is executable to some users, or if the target file is a directory.
S is the owner of the file in which the owner or group ID of the process is placed when the file is executed.
T save the program's text to the swap device.
You have the same permissions as the owner of the file.
G has the same permissions as a user with the same group as the file owner.
o have the same permissions as other users.
Example: Adding permissions to a file for execution
[Email protected] init.d]# chmod +x xkzd.sh
Digital Setting method
We must first understand the meaning of the attributes represented by numbers: 0 means no permissions, 1 means executable permissions, 2 is writable, 4 is readable
permissions, and then add them. So the format of the numeric attribute should be 3 octal numbers from 0 to 7, in the Order of (U) (g) (O).
For example, if you want the owner of a file to have "read/write" Two permissions, you need to have 4 (readable) +2 (writable) =6 (read/write).
The general form of the digital setting method is:
Syntax: chmod [mode] file name
For example: Set a file owner to read, write, execute permissions, and set the same set of users to read, execute permissions
[Email protected] init.d]# chmod xkzd.sh
Use chmod and numbers to change the access rights of a file or directory
Permissions for files and directories are represented by the rwx three characters to represent the permissions of the owner, user group, and other users. Sometimes, characters seem to be too cumbersome, so there is another way to represent permissions in numbers, and only three numbers are required.
R: Corresponding value 4 W: corresponding value 2 x: Corresponding value 1-: corresponding value 0
The key to digital setting is the value of mode, at first many beginners will be confused, in fact, it is very simple, we will rwx as a binary number, if there are 1 said, no 0 said, then rwx r-x R-can be expressed as:
111 101 100
Then convert every three bits into a decimal number, which is 754. For example, we want to have a.txt this file's permissions as: Other users of the same group as user readable Yes Yes Yes writable Yes Yes executable
So, we first get permission string according to the above table: rw-rw-r--, then convert to binary number is 110 110 100, and then every three bits into a decimal number, we get 664, so we execute the command:
[Email protected] ~]# chmod 664 a.txt
According to the above rules, rwx together is 4+2+1=7, a rwxrwxrwx permission to open the file, the value is represented as 777, and the file "---------" with completely open permission is represented as 000. Here are a few examples:
-RWX------: equals the number represents 700. -rwxr-r--: equals the number represents 744.
-rw-rw-r-x: equals the number represents 665. Drwx-x-x: equals the number represents 711. DRWX------: equals the number represents 700.
Reference: http://www.linuxeden.com/html/softuse/20100316/76103.html
Linux changes the Access command for a file or directory