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

WML tag summary

Structure related tags ---------------------------...

MySQL transaction analysis

Transaction A transaction is a basic unit of busi...

How to use indexes to optimize MySQL ORDER BY statements

Create table & create index create table tbl1...

Introduction and examples of hidden fields in HTML

Basic syntax: <input type="hidden" na...

Sharing tips on using scroll bars in HTML

Today, when we were learning about the Niu Nan new...

How to install Composer in Linux

1. Download the installation script - composer-se...

MySQL DATE_ADD and ADDDATE functions add a specified time interval to a date

MySQL DATE_ADD(date,INTERVAL expr type) and ADDDA...

How to bind domain name to nginx service

Configure multiple servers in nginx.conf: When pr...

Summary of several submission methods of HTML forms

The most common, most commonly used and most gener...

About scroll bar in HTML/removing scroll bar

1. The color of the scroll bar under xhtml In the ...

Vue must learn knowledge points: the use of forEach()

Preface In front-end development, we often encoun...

Nginx tp3.2.3 404 problem solution

Recently I changed Apache to nginx. When I moved ...

Key points for writing content of HTML web page META tags

The META tag is an auxiliary tag in the head area...

Ubuntu starts the SSH service remote login operation

ssh-secure shell, provides secure remote login. W...