Linux chmod command to modify file and folder Permissions

Source: Internet
Author: User

In linux, we need to use the linux chmod command to modify the permissions of a folder or file. Below I have written several simple examples for your reference.

Syntax: chmod [who] [+ |-| =] [mode] File Name

The meaning of each option in the command is

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. In the format of "u + s" to set the user ID of the file, and "g + s" to set the group ID.
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.

Instance

How to modify the read/write attributes of a file
For example, to change the index.html file to writable and readable, execute:

The Code is as follows: Copy code
Chmod 777 index.html

To modify the attributes of all files in the directory, perform the following operations:

The Code is as follows: Copy code
Chmod 777 *.*

Replace the folder name with the suffix.
For example, modify the attributes of all htm files:

The Code is as follows: Copy code
Chmod 777 *. htm

How to modify folder attributes
Change the directory/images/xiao to writable and readable and executable.

The Code is as follows: Copy code
Chmod 777/images/xiao

Modify all folder properties in the directory

The Code is as follows: Copy code
Chmod 777 *

Replace the folder name *.

 

To modify the attributes of all files, folders, and subfolders in a folder to writable, readable, and executable

The Code is as follows: Copy code

Chmod-R 777/upload


Summary differences between directory and file permissions in linux

File: Read the file content (r), write data to the file (w), as the command execution file (x ).
Directory: Read the file name (r) in the directory and write information to the directory (add and delete the link to the index point), search for a directory (you can use this directory name as the path name to access the files and subdirectories it contains)
Specifically:
(1) users with read-only permission cannot use cd to enter the Directory: they must also have execution permission to access.
(2) users with execution permissions can access files in the directory only when they know the file name and have the read right.
(3) You must have the read and execute permissions to list the directories in ls or use the cd command to enter the directories.
(4) You have the write permission for a directory. You can create, delete, or modify any files or subdirectories in the directory, even if the file or subdirectory belongs to another user.

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.