Linux command--chmod/chown

Source: Internet
Author: User
Tags file permissions

Change file ownership chown

For example

sudo chown username myfile
    • 1

myfileOwnership of the file becomes username .

chown -R username /files/work
    • 1

Add Parameters -R , work folders, and all the files and subdirectories in the folder are changed to ownership username .

Change file permissions chmod

chmod Modify the permissions code of a file or directory

Grammar:

chmod [Options] [Numeric or character permission representation] FileName

Options:

-C: Similar to-V, shows only the change section

-F: Do not display error messages

-R: Recursive processing

-V: Show Instruction execution process

--reference= reference file or directory

The Permission code indicates:

Permissions are divided into owner U, Group G, other O, permission code Read permission R value is 4, write permission W value is 2, execute permission x value is 1

For example: 777 represents UGO three permissions for rwx permissions.

754 means u are rwx, G is rx,o R.

You can also assign a value to a permission by using a symbol:

U=rwx,g=rx,o=r

U=rwx,go=rx

To add or remove a permission:

G-w,o-x

Go-w

For Ugo all operations with a to represent:

A=rwx

A-w

Note: chmod after modifying the permissions of the linked file, the permissions of the linked file are not changed, and the linked file is changed to the modified permission.

The meaning of rwx permissions to files and directories:

For files: r: Read the contents of a file

W: can edit or modify the contents of the file, excluding deleting files

X: This file has permissions that can be executed by the system, independent of the file suffix, and can be performed by looking at x. Can execute successfully look at the file itself.

For the directory: R: Can read the file name under the directory, LS.

W: Create a new file or directory in this directory, delete the file or directory, modify the file or directory name, move the file or directory location (CP and MV are not allowed). The permission for Path W is about the file information table under this directory. For example, in a directory where you have a rwx you have a file or directory that you do not have permission to, then you can neither read nor execute, but you have W permission in the directory, so you may delete this file or directory that you do not have permission to.

X: Permission to enter the directory. If the directory does not have X permissions, but has R permissions, the CD directory will prompt for permission not allowed. However, you can use LS to view the files in this directory.

Linux system, each user's roles and permissions are very detailed and strict, each file (directory) has access permissions, using this mechanism to determine a user in some way to read, write, execute and so on.

There are 3 different types of users who manipulate files or directories: File owners, group users, and other users. The highest bit represents the permission value of the file owner, the median is the permission value of the group user, the lowest bit represents the permission value of the other user, so, in chmod 777, three digits 7 correspond to the three users above, and the permission value is 7.

File or directory permissions are divided into 3 types: read-only, write-only, executable.

Binary
Permissions Permission Value Specific Role
R 4 00000100 Read, reading. The current user can read the contents of the file and the current user can browse the directory.
W 2 00000010 Write, writes. The current user can add or modify the contents of the file, and the current user can delete, move the directory or files within the directory.
X 1 00000001 Execute, execute. The current user can execute the file and the current user can enter the directory.

According to the above table, the permission combination is the corresponding permission value sum, as follows:

7 = 4 + 2 + 1 Read and write run permissions
5 = 4 + 1 Read and run permissions

4 = 4 read-only permission

Therefore, we also understand the meaning of the chmod 754 filename command.

This command means that the read and write permissions of the filename file are given to the owner of the file, and the permissions for reading and running are given to the group user, giving the Read permission to other users.

Linux command--chmod/chown

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.