Linux file permissions

Source: Internet
Author: User

1.chmod command

Chmod is a very important command that changes the access rights of a file or directory. Users use it to control access to files or directories.

1.1 Text Setting method

chmod [who] [+ | - | =] [mode] File name

Who's value:

    • U: Owner of file or directory
    • G: In the same group as the owner
    • O: (other) other users
    • A: All users, default values

The value of the operator:

    • +: Add
    • -: Delete
    • =: Add permissions, and remove other permissions

Mode's party:

    • R: Read permissions
    • W: Write permission
    • X: Execute permissions, file can execute with x permission, directory has x permission

Example:

    • chmod u+x test.sh, add execute permissions to the owner of the file test.sh.
    • chmod u-x test.sh, remove the Execute permission for the owning of the file test.sh.
    • chmod u+x,g-w,o-r a.txt, to file ownership add Execute permission, delete the same group of write permission, delete other people's Read permission.
    • chmod u=x a.txt, only reserved, user execute permissions on the file.
    • chmod a+r a.txt, add Read permissions to all users

1.2 Digital Setting method

The meaning of a digital representation

    • 0 means no permissions,
    • 1 indicates executable permissions,
    • 2 indicates writable permissions,
    • 4 for readable permissions

Command format:

    • chmod xxx A.txt
    • Each of the three numbers represents, the file owner, the same group of users, other users
    • The value of the data represents the permission

such as 6 = 2 + 4 that is, read and write permission; 7 = 1+2+3 is all permissions

Example

    • chmod 644 A.txt representative, the file owner has read and write permissions to the file, the same group and other users have read access to the file.
    • chmod 751 A.txt representative, the file owner of the file has read, write, execute permissions, the same group of users have read and execute permissions, other users only execute permissions on the file.

2. CHGRP command: Change the group to which the file or directory belongs

Command format

CHGRP [option] Group name file or directory name

For example: Chgrp-r groupname dirname The user group that modifies all files and directories in the directory DirName and its subdirectories is groupname

Option R, representing recursive modification

3. Chown command: Change the owner of a file or directory

chown [Options] User name file or directory name

Options:

    • -R recursively changes the owner of the specified directory and all subdirectories and files under it.
    • -V shows the work done by the Chown command.

Linux file 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.