search
HomeOperation and MaintenanceLinux Operation and MaintenanceCan 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...".

Can linux change read and write permissions?

#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).

Can linux change read and write permissions?

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.

Can linux change read and write 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
##operator:

OperatorDescriptionAdd permissions for the specified user typeRemove the permissions of the specified user type Set the settings for the specified user permissions, that is, reset all permissions of the user type
-
=
permission's symbolic pattern table:

PatternNameDescriptionread is set to Read permissionWriteSet to write permissionExecution permissionSet to executable permissionSpecial execution permissionsOnly when the file is a directory file, or other types of users have executable permissions, the file permissions are set to executablesetuid/gidWhen the file is executed, set the setuid or setgid permissions of the file according to the user type specified by the who parameterPaste bitSet the paste bit. Only the super user can set this bit, and only the file owner u can use this bit

示例:

如果我们要设定 .bashrc 文件的权限为 rwxr-xr-x,则可执行如下命令:

[root@localhost ~]# chmod u=rwx,go=rx .bashrc
[root@localhost ~]# ls -al .bashrc
-rwxr-xr-x. 1 root root 176 Sep 22 2004 .bashrc

如果想要增加 .bashrc 文件的每种用户都可做写操作的权限,可以使用如下命令:

[root@localhost ~]# ls -al .bashrc
-rwxr-xr-x. 1 root root 176 Sep 22 2004 .bashrc
[root@localhost ~]# chmod a+w .bashrc
[root@localhost ~]# ls -al .bashrc
-rwxrwxrwx. 1 root root 176 Sep 22 2004 .bashrc

八进制语法

chmod命令可以使用八进制数来指定权限。文件或目录的权限位是由9个权限位来控制,每三位为一组,它们分别是文件所有者(User)的读、写、执行,用户组(Group)的读、写、执行以及其它用户(Other)的读、写、执行。历史上,文件权限被放在一个比特掩码中,掩码中指定的比特位设为1,用来说明一个类具有相应的优先级。

r
w
x
X
s
t
# 权限 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!

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
The Building Blocks of Linux: Key Components ExplainedThe Building Blocks of Linux: Key Components ExplainedApr 30, 2025 am 12:26 AM

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.

Using Maintenance Mode: Troubleshooting and Repairing LinuxUsing Maintenance Mode: Troubleshooting and Repairing LinuxApr 29, 2025 am 12:28 AM

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.

Linux Maintenance Mode: Understanding the PurposeLinux Maintenance Mode: Understanding the PurposeApr 28, 2025 am 12:01 AM

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 Operations: Networking and Network ConfigurationLinux Operations: Networking and Network ConfigurationApr 27, 2025 am 12:09 AM

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 in Linux: A System Administrator's GuideMaintenance Mode in Linux: A System Administrator's GuideApr 26, 2025 am 12:20 AM

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.

Maintenance Mode in Linux: When and Why to Use ItMaintenance Mode in Linux: When and Why to Use ItApr 25, 2025 am 12:15 AM

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.

Linux: Essential Commands and OperationsLinux: Essential Commands and OperationsApr 24, 2025 am 12:20 AM

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.

Linux Operations: Managing Files, Directories, and PermissionsLinux Operations: Managing Files, Directories, and PermissionsApr 23, 2025 am 12:19 AM

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.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

MantisBT

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

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor