Get the App
SLTechnology News&Howtos  ›  Servers  › 

The usage of chown and chmod

Shulou Source: shulou.com Published: 2022-06-02 05:25:30 09月20日 Update

Chown usage

Used to change the user name and user group of a directory or file

Chown user name: group name file path (can be either a right path or a relative path)

Example 1:chown root:root / tmp/tmp1

Is to change the user name and user group of tmp1 under tmp to root and root (only the subordinate group of tmp1 has been modified).

Example 2:chown-R root:root / tmp/tmp1

Is to change all the files under tmp1 under tmp to root and root.

Chmod usage

Used to modify the access permissions of a directory or file.

Syntax: chmod [who] [+ |-| =] [mode] file name

The options in the command mean:

The Operand who can be any of the following letters or a combination of them:

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

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

O means "other (others) users".

A stands for "all all users". It is the system default.

The operation symbol can be:

+ add a permission.

-revoke a permission.

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

The permissions represented by mode can be set with any combination of the following letters:

R is readable.

W is writable.

X is executable.

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

S sets the process owner or group ID as the file owner of the file when the file is executed.

The user ID bit of the file is set by mode "Utility", and the group ID bit is set by "Groups".

T save the text of the program to the switching device.

U has the same permissions as the file owner.

G has the same permissions as users who belong to the same group as the file.

O have the same permissions as other users.

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

Tags: File user permission directory user name path letter that is file name user group target combination only meaning command object attribute owner text method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Information Microsoft Apple Linux