Linux chmod and Chown change the use of the owner command of the file directory

Source: Internet
Author: User

First, Chown command

Purpose: Change the owner or group of the file. The command is composed of the word change owner.

Examples of Use:

1. Change the owner of the file:

Chown Jim Program.c

Change the owner of the file program.c to Jim. As an owner, Jim can use the chmod command to allow or deny other users access to PROGRAM.C.

2. Change the owner of the directory:

Chown-r JOHN:BUILD/TMP/SRC

Change the owner and group of all files in directory/tmp/src to user John and group build

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

Second, chmod command

Purpose: Changes the access rights of a file or directory.

There are two ways to use this command:
One is a text-setting method that contains letters and operator expressions, and the other is a digital setting method that contains numbers.

1, text setting method

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

The meanings of the options in the command are:

Action object who is either or a combination of the following letters:

U means "user", which is the owner of the file or directory.

G means "same group user", that is, all users who have the same group ID as the file owner.

O means "other (others) users".

A means "all users". It is the system default value.

The operation symbols can be:

+ Add a permission.

-Cancels a permission.

= gives the given permission and cancels all other permissions, if any.

Setting the permissions represented by mode can be any combination of the following letters:

R is readable.

W writable.

X executable.

x append the x attribute only if the destination file is executable to some users, or if the target file is a directory.

S is the owner of the file in which the owner or group ID of the process is placed when the file is executed. The way "U+s" sets the user ID bit of the file, "G+s" sets the group ID bit.

T save the program's text to the swap device.

You have the same permissions as the owner of the file.

G has the same permissions as a user with the same group as the file owner.

o have the same permissions as other users.

File name: A list of files separated by spaces to change permissions, and wildcard characters are supported.

Multiple permission methods can be given in one command line, separated by commas. Example: chmod g+r,o+r Example

Enables the same group and other users to have read access to the file example.

2, digital setting method

We must first understand the meaning of the attributes represented by numbers: 0 means no permissions, 1 means executable permissions, 2 is writable, 4 is read, and then it is added.

So the format of the numeric attribute should be 3 octal numbers from 0 to 7, in the Order of (U) (g) (O).

For example, if you want the owner of a file to have "read/write" Two permissions, you need to have 4 (readable) +2 (writable) =6 (read/write).

The general form of the digital setting method is:

chmod [mode] file name

Linux chmod and Chown change the use of the owner command of the file directory

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.