How to use the Linux chmod command

Source: Internet
Author: User
Tags chmod readable

Linux/Unix file calling permissions are divided into three levels: file owner, group, and others. Chmod can be used to control how files are called by others.

Permission: all users

Syntax

Chmod [-cfvR] [-- help] [-- version] mode file...

Parameter description

  • Mode: permission setting string in the following format: [ugoa...] [[+-=] [rwxX]...] [,...]
    Where:

    • U indicates the owner of the file, g indicates that the owner of the file belongs to the same group, o indicates other people, and 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 of the file has been changed, the change action is displayed.

  • -F: If the file permission cannot be changed, do not display an error message.

  • -V: displays details of permission changes.

  • -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: displays auxiliary instructions

  • -- Version: displays the version.

Instance

Set file1.txt to readable by all users:

Chmod ugo + r file1.txt

Set file1.txt to readable by all users:

Chmod a + 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 also use numbers to indicate permissions, for example:

Chmod777file

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 the rw-attribute is required, 4 + 2 = 6;

  • If you want the r-x attribute, 4 + 1 = 5.

Chmod a = rwx file

And

Chmod777file

Same effect

Chmod ug = rwx, o = x file

And

Chmod771file

Same effect

If chmod 4755 filename is used, the program can have root permissions.

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.