Chmod changes folder or File Permissions

Source: Internet
Author: User

Chmod is one of the common commands in linux. It is mainly used to change the permissions of folders or files. It is often used in website deployment.

This command is executed by the root user or the user granted the relevant permissions.

Command Format: chmod [-cfvR] [-- help] [-- version] file or folder

Parameter description:

Permission setting string in the following format:
[Ugoa] [[+-=] [rwxX]...] [,...], u indicates the owner of the file or directory, g indicates that the owner of the file or directory belongs to the same group, and o indicates the owner of other files or directories, a indicates that all three are. + Adds a permission,-Indicates canceling the permission, and = indicates a unique permission. R indicates that the file can be read, w indicates that the file can be written, and x indicates that the file can be executed only when the file is a subdirectory or the file has been set to executable. -C: if the permission has been changed, the change action is displayed.-f: if the permission cannot be changed, no error message is displayed.-v: detailed information about permission change-R: change the permissions of all files and sub-directories in the current directory in the same way (that is, change one by one in the way of delivery) -- help: display auxiliary instructions -- version: display version
Example:

Set file1.txt to readable by all users:
chmod ugo+r file1.txt
Set file1.txt and file2.txt as the owner of the file, which can be written to the same group, but not to others:
chmod ug+w,o-w file1.txt file2.txt
Set ex1.py to be executed only by the file owner:
chmod u+x ex1.py
Set all files and subdirectories in the current directory to be readable by anyone:
chmod -R a+r *  
In addition, chmod can use numbers to indicate permissions, such as chmod 777 file.

Syntax: chmod abc file

Each a, B, and c is a number, indicating the permissions of the User, Group, and Other respectively.

R = 4, w = 2, x = 1 if you want the rwx attribute, 4 + 2 + 1 = 7; if you want the rw-attribute, 4 + 2 = 6; if you want the r-x attribute, 4 + 1 = 7.
For example:

Chmod a = rwx file and chmod 777 file have the same effect

Chmod ug = rwx, o = x file, and chmod 771 file have the same effect.

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.