Home > Article > Operation and Maintenance > Can linux change read and write permissions?
Linux can change read and write permissions. In Linux, you can use the chmod command to modify read and write permissions. This command can control user permissions on files. You can use octal number mode or symbolic mode to set read and write permissions. The syntax is "chmod [-cfvR] [--help] mode file...".
#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.
Linux can change the read and write permissions.
In Linux, you can use the chmod command to modify read and write permissions.
Linux chmod (English full spelling: change mode) command is a command that controls user permissions on files
Linux/Unix file calling permissions are divided into three levels: File Owner (Owner) , user group (Group), other users (Other Users).
Only the file owner and superuser can modify the permissions of a 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]...][,...]
where:
u represents the owner of the file, g represents the person who belongs to the same group as the owner of the file, o means someone other than someone else, and a means 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.
Option description:
-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 the 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
Symbol mode
Use Symbolic mode can set multiple items: who (user type), operator (operator) and permission (permission). The settings of each item can be separated by commas. The command chmod will modify the file access permissions of the user type specified by who. The user type is described by one or more letters in the position of who, as shown in the symbol pattern table of who:
who | User Type | Description |
---|---|---|
u | user | File owner |
g | group | File owner’s group |
o | others | All other users |
a | The user used by all | is equivalent to the symbol pattern table of ugo |
Description | |
---|---|
Add permissions for the specified user type | |
- | Remove the permissions of the specified user type|
= | Set the settings for the specified user permissions, that is, reset all permissions of the user type
Name | Description | ||
---|---|---|---|
r | readis set to Read permission | ||
w | WriteSet to write permission | ||
x | Execution permissionSet to executable permission | ||
X | Special execution permissionsOnly when the file is a directory file, or other types of users have executable permissions, the file permissions are set to executable | ||
s | setuid/gidWhen the file is executed, set the setuid or setgid permissions of the file according to the user type specified by the who parameter | ||
t | Paste bitSet the paste bit. Only the super user can set this bit, and only the file owner u can use this bit |
# | 权限 | rwx | 二进制 |
---|---|---|---|
7 | 读 + 写 + 执行 | rwx | 111 |
6 | 读 + 写 | rw- | 110 |
5 | 读 + 执行 | r-x | 101 |
4 | 只读 | r-- | 100 |
3 | 写 + 执行 | -wx | 011 |
2 | 只写 | -w- | 010 |
1 | 只执行 | --x | 001 |
0 | 无 | --- | 000 |
例如, 765 将这样解释:
所有者的权限用数字表达:属主的那三个权限位的数字加起来的总和。如 rwx ,也就是 4+2+1 ,应该是 7。
用户组的权限用数字表达:属组的那个权限位数字的相加的总和。如 rw- ,也就是 4+2+0 ,应该是 6。
其它用户的权限数字表达:其它用户权限位的数字相加的总和。如 r-x ,也就是 4+0+1 ,应该是 5。
示例:
使用如下命令,即可完成对 .bashrc 目录文件的权限修改:
[root@localhost ~]# ls -al .bashrc -rw-r--r--. 1 root root 176 Sep 22 2004 .bashrc [root@localhost ~]# chmod 777 .bashrc [root@localhost ~]# ls -al .bashrc -rwxrwxrwx. 1 root root 176 Sep 22 2004 .bashrc
再举个例子,通常我们以 Vim 编辑 Shell 文件批处理文件后,文件权限通常是 rw-rw-r--
(644),那么,如果要将该文件变成可执行文件,并且不让其他人修改此文件,则只需将此文件的权限该为 rwxr-xr-x
(755)即可。
相关推荐:《Linux视频教程》
The above is the detailed content of Can linux change read and write permissions?. For more information, please follow other related articles on the PHP Chinese website!