


How to modify file permissions in linux
In Linux, you can use the chmod command to modify file permissions. It is a command that controls user permissions on files. You can use absolute mode (octal number mode) or symbolic mode to specify file permissions; syntax " chmod [-R] permission value filename".
#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.
In Linux, you can use the chmod command to modify file permissions.
The chmod (full English 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), and 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.
chmod command uses numbers to modify file permissions
In the Linux system, the basic permissions of a file consist of 9 characters. Taking rwxrw-r-x as an example, we can use numbers to represent each permission. The corresponding relationship between each permission and the number is as follows:
r --> 4 w --> 2 x --> 1
Since these 9 characters belong to 3 types of users, each user identity contains 3 permissions (r, w, x). Add up the numbers corresponding to the three permissions, and the final value can be used as the permissions of each user.
Take rwxrw-r-x as an example. The permission values corresponding to the owner, the group to which it belongs and other people are:
Owner = rwx = 4 2 1 = 7
Group = rw- = 4 2 = 6
Others = r-x = 4 1 = 5
So, the permission value corresponding to this permission is 765.
The basic format of the chmod command that uses numbers to modify file permissions is:
[root@localhost ~]# chmod [-R] 权限值 文件名
-R
(note that it is capitalized) The option indicates that together with the subdirectory All files also have modified permissions.
For example, use the following command to modify the permissions of the .bashrc directory file:
[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
For another example, we usually use Vim to edit the Shell file batch After processing the file, the file permissions are usually rw-rw-r-- (644). Then, if you want to turn the file into an executable file and prevent others from modifying this file, you only need to change the permissions of this file. Just rwxr-xr-x (755).
The chmod command uses letters to modify file permissions
Since the basic permissions of a file are 3 types of user identities (owner, group and others) with 3 Three kinds of permissions (rwx). In the chmod command, u, g, and o are used to represent three identities respectively, and a is used to represent all identities (the abbreviation of all). In addition, the chmod command still uses r, w, and x to represent read, write, and execute permissions respectively.
The chmod command uses letters to modify file permissions. Its basic format is as shown in the figure below.
For example, if we want to set the permissions of the .bashrc file to rwxr-xr-x
, we can execute the following command:
[root@localhost ~]# chmod u=rwx,go=rx .bashrc [root@localhost ~]# ls -al .bashrc -rwxr-xr-x. 1 root root 176 Sep 22 2004 .bashrc
For another example, if you want to increase the writing permissions of each user in the .bashrc
file, you can use the following command:
[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
Related recommendations: "Linux video tutorial》
The above is the detailed content of How to modify file permissions in linux. For more information, please follow other related articles on the PHP Chinese website!

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The steps to start Apache are as follows: Install Apache (command: sudo apt-get install apache2 or download it from the official website) Start Apache (Linux: sudo systemctl start apache2; Windows: Right-click the "Apache2.4" service and select "Start") Check whether it has been started (Linux: sudo systemctl status apache2; Windows: Check the status of the "Apache2.4" service in the service manager) Enable boot automatically (optional, Linux: sudo systemctl

When the Apache 80 port is occupied, the solution is as follows: find out the process that occupies the port and close it. Check the firewall settings to make sure Apache is not blocked. If the above method does not work, please reconfigure Apache to use a different port. Restart the Apache service.

To restart the Apache server, follow these steps: Linux/macOS: Run sudo systemctl restart apache2. Windows: Run net stop Apache2.4 and then net start Apache2.4. Run netstat -a | findstr 80 to check the server status.

Apache cannot start because the following reasons may be: Configuration file syntax error. Conflict with other application ports. Permissions issue. Out of memory. Process deadlock. Daemon failure. SELinux permissions issues. Firewall problem. Software conflict.

This guide will guide you to learn how to use Syslog in Debian systems. Syslog is a key service in Linux systems for logging system and application log messages. It helps administrators monitor and analyze system activity to quickly identify and resolve problems. 1. Basic knowledge of Syslog The core functions of Syslog include: centrally collecting and managing log messages; supporting multiple log output formats and target locations (such as files or networks); providing real-time log viewing and filtering functions. 2. Install and configure Syslog (using Rsyslog) The Debian system uses Rsyslog by default. You can install it with the following command: sudoaptupdatesud

The Internet does not rely on a single operating system, but Linux plays an important role in it. Linux is widely used in servers and network devices and is popular for its stability, security and scalability.

Steps to fix the Apache vulnerability include: 1. Determine the affected version; 2. Apply security updates; 3. Restart Apache; 4. Verify the fix; 5. Enable security features.

Steps to start Nginx in Linux: Check whether Nginx is installed. Use systemctl start nginx to start the Nginx service. Use systemctl enable nginx to enable automatic startup of Nginx at system startup. Use systemctl status nginx to verify that the startup is successful. Visit http://localhost in a web browser to view the default welcome page.
