Modify file and folder permissions in Linux

Source: Internet
Author: User

Original article address:

 

A number indicates the file permissions of other user groups.
Linux File permissions are divided into three types:

Read (r = 4), write (W = 2), and execute (x = 1 ). In combination, there are also readable executable (RX = 5 = 4 + 1) and readable writable (RW = 6 = 4 + 2), readable and writable (rwx = 7 = 4 + 2 + 1 ).
Rwx = 7 (that is, binary 111 ----- decimal 7) RW-= 6 (Binary 110 ------ decimal 6) r-x = 5 (Binary 101 -------- decimal 5)
-WX = 3 (Binary 011 ------- decimal 3)

774 permission: 111 111 101 rwxrwxr -- indicates that the owner of this folder and the group to which the owner belongs have the read and write executable permissions, while other users only have the read permission.

Similarly, 777 of permissions are 111, 111, and 111.

755 permission is 111 101 101

 

 

View the file owner

Stat-C % U filename

First, let's take a look at the file attributes,
In the shell environment, enter LS-L to view the current directory file. For example:

Drwxr-XR-x 2 NSF users 1024 12-10 download file backup

They correspond:
File Attribute connection count file owner group file size file modification time file name
Here, R is readable, W is writable, and X is executable. The file attributes are divided into four sections and ----10 positions.
For example:

D rwx R-x r-x
The first character specifies the file type. In general, a directory is also a file. If the first character is a horizontal line, it indicates a non-directory file. If it is D, it indicates a directory.

The second part is the attributes of the file owner,

The third section is the attributes of the group to which the file belongs,
The fourth section is the attributes of other users,


 

For example, the "download file backup" permission in the above folder indicates that the "download file backup" folder is a directory file; the owner of the "download file backup" folder has the read and write permissions; users in the same group as the folder "download file backup" have only the read and executable permissions. Other users also have the read and executable permissions.
After determining the access permission for a file, you can use the CHMOD command provided by Linux to reset different access permissions. 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 of a file or directory.
Chmod command
Function: the CHMOD command is very important and used to change the access permissions of files or directories. You can use it to control the access permissions of files or directories.
Syntax: This command can be used in two ways. One is the text setting method that contains letters and operator expressions, and the other is the number setting method that contains numbers.
1. text setting method

Chmod [who] [+ |-| =] [mode] File Name?

Parameters:
The operator who is one of the following letters or their combination:

U indicates "user", that is, the owner of a file or directory.

G indicates "group users", that is, all users with the same group ID as the file owner.
O indicates "Other (Others) Users ".
A Indicates "All (all) Users ". It is the default value of the system.
The operation symbol can be:
+ Add a permission.
-Cancel a permission.
= Grant the given permission and cancel all other permissions (if any ).

 

Set the permissions indicated by mode to any combination of the following letters:

R readable.

W writable.
X executable.
X adds the X attribute only when the target file is executable to some users or the target file is a directory.
S sets the owner or group ID of the process to the file owner during file execution. Method "U + S" to set File Usage & nbsp; User ID, "G + S" sets the group ID bit.
T saveProgram.
U has the same permissions as the file owner.
G. users in the same group have the same permissions as file owners.
O has the same permissions as other users.


File Name: list of files separated by spaces to change permissions. Wildcards are supported.
Multiple permission methods can be provided in a command line, separated by commas. Example: chmod g + R, O + r example
Grant the same group and other users the permission to read the file example.
Chgrp command
Function: Change the group to which a file or directory belongs.
Syntax: chgrp [Option] group filename?
This command changes the user group to which the specified file belongs. The Group can be either the user group ID or the group name of the user group in the/etc/group file. A file name is a list of files separated by spaces to change the group. Wildcards are supported. If the user is not the owner or super user of the file, the file group cannot be changed.
Parameters:
-R recursively changes the group of all subdirectories and files in a specified directory.
Example 1:

$ Chgrp  -R book/opt/ Local  /Book

Change the owner group of all files in/opt/local/book/and its subdirectories to book.
CHOWN command
Function: Modify the owner and group of a file or directory. This command is also very common. For example, if the root user copies a file to Xu, the root user should set the owner of the file to Xu to allow Xu to access the file. Otherwise, user Xu cannot access this file.
Syntax: chown [Option] user or group file
Note: chown will change the owner of a specified file to a specified user or group. Users can be user names or user IDs. A group can be a group name or group ID. Files are separated by spaces to change the permission list. Wildcards are supported.
Parameters:

-R recursively changes the owner of all subdirectories and files under a specified directory.

-V DisplayChownCommand.

Example 1: Change the owner of the Shiyan. c file to Wang.

  Chown  Wang Shiyan. c

Example 2: Change the owner of the directory/his and all files and subdirectories to Wang and the group to users.

$ Chown  -R Wang. Users  /His

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.