LinuxShell Command Interpreter: permission management chmod

Source: Internet
Author: User
Article Title: LinuxShell Command Interpreter: permission management chmod. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Chmod is used to change the access permissions of files or directories. You can use it to control access to files or directories. This command can be used in two ways. One is the text setting method that contains letters and operator expressions, and the other is the number setting method that contains numbers.

1. text setting method

Syntax: chmod [who] [+ |-| =] [mode] File Name

The meaning of each option in the command is:

The operator who is one of the following letters or their combination:

U indicates "user", that is, the owner of a file or directory.

G indicates "group users", that is, all users with the same group ID as the file owner.

O indicates "Other (others) Users ".

A Indicates "all (all) Users ". It is the default value of the system.

The operation symbol can be:

+ Add a permission.

-Cancel a permission.

= Grant the given permission and cancel all other permissions (if any ).

Set the permissions indicated by mode to any combination of the following letters:

R readable.

W writable.

X executable.

X adds the x attribute only when the target file is executable to some users or the target file is a directory.

S sets the owner or group ID of the process to the file owner during file execution.

In the format of "u + s" to set the user ID of the file, and "g + s" to set the group ID.

T save the program text to the swap device.

U has the same permissions as the file owner.

G. users in the same group have the same permissions as file owners.

O has the same permissions as other users.

File Name: list of files separated by spaces to change permissions. Wildcards are supported.

Multiple permission methods can be provided in a command line, separated by commas. For example:

Chmod g + r, o + r example % enables the same group and other users to have read permission on the file example.

2. Number setting method

First, we must understand the meaning of the property represented by numbers: 0 indicates no permission, 1 indicates executable permission, 2 indicates writable permission, 4 indicates readable permission, and then add it. Therefore, the format of the numeric attribute should be three Octal numbers from 0 to 7. The order is (u) (g) (o ).

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

The number setting method is generally in the following format:

Syntax: chmod [mode] File Name

Command instance:

Chmod a + x sort

% Sets the property of the file sort:

File owner (u) adds execution permission

Add execution permission for users in the same group as the file owner (g)

Other users (o) add execution Permissions

Chmod ug + w, o-x text

% Indicates that the attribute of the file text is:

Add write permission to file owner (u)

Add write permission for users in the same group as the file owner (g)

Other users (o) delete execution Permissions

Chmod u + s a. out

% Assume that the permission for a. out after chmod execution is (you can use ls? L a. out command ):

? Rws -- x 1 inin users 7192 Nov 4 14:22 a. out

In addition, this execution file uses a text file shiyan1.c, whose file access permission is "? Rw --",

That is, only the owner of the file has read and write permissions.

When another user executes the. out Program, his identity becomes inin because of this program temporarily (because chmod

Command), so he can read the shiyan1.c file (although this file is set

Others do not have any permissions). This is the function of s.

Therefore, in the entire system, especially the root itself, it is best not to set too many files of this type (unless

Necessary) This ensures system security and prevents system intrusion due to bugs in some programs.

Chmod? X mm.txt

Chmod? X mm.txt

Chmod ugo? X mm.txt

% All these three commands Delete the execution permission of the mm.txt file, and the object set by the command is all users.

$ Chmod 644 mm.txt

% Sets the attributes of the file mm.txt to-rw-r --

File owner (u) inin has read and write permissions

Users in the same group as the file owner (g) have read permission

Others (o) have read permission

Chmod 750 wch.txt

% Sets the property of the wchtxt file to-rwxr-x --

File owner (u) inin readable/writable/executable

Readable/executable permission of persons in the same group as the file owner

Others (o) do not have any 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.