


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!

The core components of the Linux system include the kernel, file system, and user space. 1. The kernel manages hardware resources and provides basic services. 2. The file system is responsible for data storage and organization. 3. Run user programs and services in the user space.

Maintenance mode is a special operating level entered in Linux systems through single-user mode or rescue mode, and is used for system maintenance and repair. 1. Enter maintenance mode and use the command "sudosystemctlisolaterscue.target". 2. In maintenance mode, you can check and repair the file system and use the command "fsck/dev/sda1". 3. Advanced usage includes resetting the root user password, mounting the file system in read and write mode and editing the password file.

Maintenance mode is used for system maintenance and repair, allowing administrators to work in a simplified environment. 1. System Repair: Repair corrupt file system and boot loader. 2. Password reset: reset the root user password. 3. Package management: Install, update or delete software packages. By modifying the GRUB configuration or entering maintenance mode with specific keys, you can safely exit after performing maintenance tasks.

Linux network configuration can be completed through the following steps: 1. Configure the network interface, use the ip command to temporarily set or edit the configuration file persistence settings. 2. Set up a static IP, suitable for devices that require a fixed IP. 3. Manage the firewall and use the iptables or firewalld tools to control network traffic.

Maintenance mode plays a key role in Linux system management, helping to repair, upgrade and configuration changes. 1. Enter maintenance mode. You can select it through the GRUB menu or use the command "sudosystemctlisolaterscue.target". 2. In maintenance mode, you can perform file system repair and system update operations. 3. Advanced usage includes tasks such as resetting the root password. 4. Common errors such as not being able to enter maintenance mode or mount the file system, can be fixed by checking the GRUB configuration and using the fsck command.

The timing and reasons for using Linux maintenance mode: 1) When the system starts up, 2) When performing major system updates or upgrades, 3) When performing file system maintenance. Maintenance mode provides a safe and controlled environment, ensuring operational safety and efficiency, reducing impact on users, and enhancing system security.

Indispensable commands in Linux include: 1.ls: list directory contents; 2.cd: change working directory; 3.mkdir: create a new directory; 4.rm: delete file or directory; 5.cp: copy file or directory; 6.mv: move or rename file or directory. These commands help users manage files and systems efficiently by interacting with the kernel.

In Linux, file and directory management uses ls, cd, mkdir, rm, cp, mv commands, and permission management uses chmod, chown, and chgrp commands. 1. File and directory management commands such as ls-l list detailed information, mkdir-p recursively create directories. 2. Permission management commands such as chmod755file set file permissions, chownuserfile changes file owner, and chgrpgroupfile changes file group. These commands are based on file system structure and user and group systems, and operate and control through system calls and metadata.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor
