Home >Operation and Maintenance >Linux Operation and Maintenance >How to modify permissions in linux

How to modify permissions in linux

WBOY
WBOYOriginal
2022-01-27 11:40:2625460browse

In Linux, you can use the chmod command to modify file permissions. The function of this command is to control the user's permissions on files. The syntax is "chmod [-cfvR] [--help] [--version] mode file ...".

How to modify permissions in linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How to modify permissions in Linux

Linux chmod (English full spelling: change mode) command is a command to control user permissions on files

Linux/Unix file calling permissions It is three levels: file owner (Owner), user group (Group), and other users (Other Users).

Only the file owner and superuser can modify the permissions of the file or directory. You can use absolute mode (octal number mode) and symbolic mode to specify file permissions.

Usage permissions: all users

Syntax

chmod [-cfvR] [--help] [--version] mode file...

Parameter description

mode: Permission setting string, the format is as follows:

[ugoa...][[+-=][rwxX]...][,...]

Among them:

  • u represents the owner of the file, g represents the person who belongs to the same group as the owner of the file, o represents other people, and a represents It's all three.

  • means adding permissions, - means canceling permissions, = means setting only permissions.

  • r means readable, w means writable, x means executable, and X means only when the file is a subdirectory or the file has been set to be executable.

Other parameter descriptions:

  • -c: If the file permissions have indeed been changed, the change action will be displayed

  • -f : Do not display an error message if the file permissions cannot be changed

  • -v : Display details of permission changes

  • -R: Make the same permission changes to all files and subdirectories in the current directory (that is, change them one by one recursively)

  • --help: Display auxiliary instructions

  • --version: Display version

There are nine basic permissions for Linux files, which are owner/group/others. Each has its own read/write/execute permissions

Example: The permission character of the file is -rwxrwxrwx These nine permissions are in groups of three! Among them, we can use numbers to represent each permission. The score comparison table for each permission is as follows:

r:4  w:2  x:1

Each identity (owner/group/others) The respective three permissions (r/w/x) scores need to be accumulated. For example, when the permissions are: [-rwxrwx---] the score is:

owner = rwx = 4+2+1 = 7
group = rwx = 4+2+1 = 7
others= --- = 0+0+0 = 0

So when we set the permission changes, The permission number of this file is 770! The syntax of the chmod command to change permissions is as follows:

[root@www ~]# chmod [-R] xyz 档案或目录

Options and parameters:

  • xyz: It is the numeric type permission attribute just mentioned, which is the rwx attribute Addition of values.

  • -R: Perform recursive continuous changes, that is, all files in the sub-directory will be changed

For example , if you want to set and enable all permissions of the .bashrc file, then issue:

[root@www ~]# ls -al .bashrc 
-rw-r--r-- 1 root root 395 Jul 4 11:45 .bashrc 
[root@www ~]# chmod 777 .bashrc 
[root@www ~]# ls -al .bashrc 
-rwxrwxrwx 1 root root 395 Jul 4 11:45 .bashrc

What if you want to change the permissions to -rwxr-xr--? Then the permission score becomes [4 2 1][4 0 1][4 0 0]=754! So you need to issue:

[root@www ~]# chmod 754 filename

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of How to modify permissions in linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn