How to change Linux folder Permissions

Source: Internet
Author: User

For details about how to change Linux folder permissions, enter ls-l in the shell environment to view the current directory file. For example, drwxr-xr-x 2 nsf users 1024 12-10 download file backup corresponding: file Attribute connections file owner group file size file modification time file name here r is readable, w writable, x executable, where file attributes are divided into four sections, ---- --- 10 locations for example: the first character of d rwx r-x 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 part is the attributes of the group to which the file belongs, and the fourth part is the attributes of other users, such as the access permission for the folder "download file backup" above, 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 for changing the access permissions of files or directories. You can use it to control the access permissions of files or directories. Syntax: This command has two usage methods. 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? Parameter: The operation object 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 expressed 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. In the format of "u + s", set the user ID bit of the file, and "g + s" to set the group ID bit. T save the program text to the swap device. 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. For example, chmod g + r, o + r example enables the same group and other users to have the read permission on the file example. The chgrp command function is used to 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. Parameter:-R recursively modifies the group of all subdirectories and files under a specified directory. Example 1: $ chgrp-R book/opt/local/book changes the 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 Description: chown changes the owner of the specified file to the 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. Parameter:-R recursively modifies the owner of all subdirectories and files under a specified directory. -V: displays the work done by the chown command. 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 change the group to users. $ Chown-R wang. users/his usage: chmod [-cfvR] mode file Description: file access permissions for Linux/Unix are classified into three levels: Owner, group, and others. Chmod can be used to control the permission to read files. Mode: permission setting string in the following format: [ugoa...] [+-=] [rwxX], where u indicates the file owner (user) and g indicates that the file owner belongs to the same group ), o indicates others (other), and a indicates all ). + Adds a permission,-Indicates canceling the permission, and = indicates a unique permission. R indicates readable, w indicates writable, and x indicates executable. -F: if the file permission cannot be changed, do not display the error message-v: detailed information about permission change-R: for example, to change the permissions of all files and subdirectories in the current directory one by one (that is, to change the permissions one by one), set file1.txt to readable: chmod ugo + r file1.txt sets the archive file1.txt and file2.txt as the owner of the archive, which can be written to the same group as the archive owner, but cannot be written to others: chmod ug + w, o-w file1.txt file2.txt sets the directory log and all files in the directory as the owner of the file to write, read, and execute. The owner of the file can read and execute the file. Chmod-R 755 log

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.