Detailed analysis of the chmod command to modify file permissions under Linux

Detailed analysis of the chmod command to modify file permissions under Linux

Use the Linux chmod command to control who can access, read, write, or run the target file .

In Linux, who can do what with a file or directory is controlled through a set of permissions.

Permissions control the operations (read, write, or execute) that can be performed on a file or directory.

We can use the -l (long format) option to ls to list the file permissions for files and directories.

ls -l 

In each line, the first character identifies the type of entry listed. If it is a dash ( - ), it is a file. If it is the letter d , it is a directory.

The next nine characters represent three sets of permission settings.

The first three characters show the permissions of the user who owns the file ( User Rights ).

The middle three characters show the permissions of the user group membership ( group permissions ).

The last three characters show permissions for anyone outside the first two categories ( other permissions ).

There are three characters in each set of permissions. The character is an indicator of whether the permission is present or not. They are either a dash ( - ) or a letter. If the character is a dash, it means that permission is not granted. If the character is an r , w , or x , the permission is granted.

The letters represent:

r : Read permission. You can open the file and view its contents.

w : write permission. This file can be edited, modified and deleted.

x : Execute permission. If the file is a script or program, it can be run (executed).

For example:

--- means no permissions are granted at all.

rwx means full permissions are granted. Read, write, and execute indicators are present.

Syntax for setting permissions

To set permissions with chmod , we need to tell it:

who : For whom we are setting permissions.

what : What changes are we making? Are we adding or removing permissions?

which: Which permissions did we set?

We use indices to represent these values ​​and form short "permission statements" such as u+x , where "u" stands for "current user" (who), "+" stands for addition ( what ), and "x" stands for execute permission (which).

The "who" values ​​we can use are:

u : user, indicating the owner of the file.

g : Group, indicating the members of the group to which the file belongs.

o : Others, meaning people who are not managed by u and g permissions.

a : All, meaning all of the above.

The values ​​we can use for " what " include:

: Minus sign. Remove permissions.

+ : Plus sign. Grant permissions. The permission is added to the existing permissions. If you want to have this permission and only set this permission, use the = option as described below.

= : equal sign. Set permissions and remove others.

The "which" values ​​we can use are:

r : Read permission.

w : write permission.

x : Execute permission.

Examples:

We can add execute permissions for everyone with the following command:

chmod a+x new_script.sh 

We want user dave to have read and write permissions, while group and other users have only read permissions. We can use the following command:

chmod u=rw,og=r new_file.txt 

Using the "=" operator means we clear all existing permissions and then set the specified permissions.

This is the end of this article about the detailed analysis of the chmod command to modify file permissions under Linux. For more relevant Linux chmod command content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Modify file permissions (ownership) under Linux
  • Linux common commands chmod to modify file permissions 777 and 754
  • Linux server programming utime() function to modify file access time
  • How to modify the user and group of a file in Linux

<<:  Example code for implementing beautiful clock animation effects with CSS

>>:  Detailed explanation of html printing related operations and implementation

Recommend

Detailed tutorial on compiling and installing MySQL 5.7.24 on CentOS7

Table of contents Install Dependencies Install bo...

Three common style selectors in html css

1: Tag selector The tag selector is used for all ...

Linux dual network card binding script method example

In Linux operation and configuration work, dual n...

Super detailed steps to install zabbix3.0 on centos7

Preface Recently, part of the company's busin...

Sample code for a simple seamless scrolling carousel implemented with native Js

There are many loopholes in the simple seamless s...

How to uninstall MySQL 5.7 on CentOS7

Check what is installed in mysql rpm -qa | grep -...

Tips for optimizing MySQL SQL statements

When faced with a SQL statement that is not optim...

Summary of things to pay attention to in the footer of a web page

Lots of links You’ve no doubt seen a lot of sites ...

Detailed graphic tutorial on installing Ubuntu 20.04 dual system on Windows 10

win10 + Ubuntu 20.04 LTS dual system installation...

Implementation steps for Docker deployment of SpringBoot applications

Table of contents Preface Dockerfile What is a Do...

Image scrolling effect made with CSS3

Achieve resultsImplementation Code html <base ...

JavaScript Composition and Inheritance Explained

Table of contents 1. Introduction 2. Prototype ch...

Does Mysql ALTER TABLE lock the table when adding fields?

Table of contents Before MySQL 5.6 After MySQL 5....

Detailed explanation of browser negotiation cache process based on nginx

This article mainly introduces the detailed proce...