Detailed explanation of chmod command usage in Linux

Detailed explanation of chmod command usage in Linux

chmod Command Syntax

This is the correct syntax when using the chmod command:

chmod [options] mode [,mode] file1 [file2 ...]

Here are some common options used with chmod:

● -f, --silent, --quiet (suppress most error messages)

● -v, --verbose (output diagnostic information for each file processed)

● -c, --changes (similar to verbose but reports only when changes were made)

● -R, --recursive (recursively change files and directories)

● --help (show help and exit)

● --version (output version information and exit)

Below is a list of several numeric permissions that can be set for users, groups, and everyone else on the computer. Next to the number is the Read/Write/Execute letter equivalent.

● 7: indicates rwx, which has read, write and execute permissions

● 6: indicates rw-, which means read and write permissions

● 5: indicates rx, which has read and execute permissions

● 4: indicates r--, with read-only permission

● 3: means -wx, has write and execute permissions

● 2: means -w-, has write-only permission

● 1: indicates - x, only has execution permission

● 0: means ---, no permission

Note: If you need to list the permissions of a file, you need to use the ls command.

chmod Command Examples

If a user wants to change the permissions of the file "participants" so that everyone has full access to the file, they would enter the following command:

chmod 777 participants

Note: The first 7 sets the user's permissions, the second 7 sets the group's permissions, and the third 7 sets the permissions for other owners.

If the user wants to be the only one who can access it, he can use the following command:

chmod 700 participants

To provide full access permissions to yourself and your group members, you can use the following command:

chmod 770 participants

If a user wants to retain full access for themselves, but want to prevent others from modifying the file, they can use the following command:

chmod 755 participants

The following uses the letters above to change the permissions of the file "participants" so that the owner can read and write the file, but does not change the permissions for anyone else:

chmod u=rw participants

Setting Mode

Use the chmod command to set additional file system modes for files and directories. For example, to set the sticky bit — which means only the file owner, directory owner, or superuser can delete the file, regardless of the file's read-write group permissions — add 1 to the front of the number sequence:

chmod 1755 participants

other:

Users can also change the group ownership of existing files and folders using the chgrp command and the newgrp command to change the default group for new files and folders.

Remember that symbolic links used in the chmod command will affect the real target object.

You may also be interested in:
  • Explanation of building graph database neo4j in Linux environment
  • How to install the standalone version of spark in linux environment without using hadoop
  • Build a Scala environment under Linux and write a simple Scala program
  • Common Linux English Error Chinese Translation (Newbies Must Know)
  • How to enter directory/folder in Linux without using CD command
  • Three ways to check whether a port is open in a remote Linux system
  • Detailed Linux installation tutorial
  • Detailed instructions for installing Swoole from source code package under Linux and basic usage operations
  • Explanation of several ways to run Tomcat under Linux
  • View the dependent libraries of so or executable programs under linux

<<:  Tutorial on how to install and configure the unzipped version of MySql under Windows 10

>>:  Share some tips on using JavaScript operators

Recommend

Introduction to the role of HTML doctype

Document mode has the following two functions: 1. ...

Install Ubuntu 18 without USB drive under Windows 10 using EasyUEFI

1. Check BIOS First check which startup mode your...

Enabling or disabling GTID mode in MySQL online

Table of contents Basic Overview Enable GTID onli...

MySQL Series Database Design Three Paradigm Tutorial Examples

Table of contents 1. Knowledge description of the...

Solve the problem that ElementUI custom CSS style does not take effect

For example, there is an input box <el-input r...

Centos8 bridge static IP configuration method in VMware virtual machine

1. Make sure the network connection method is bri...

CSS World--Code Practice: Image Alt Information Presentation

Using the <img> element with the default sr...

JavaScript implements div mouse drag effect

This article shares the specific code for JavaScr...

4 ways to implement routing transition effects in Vue

Vue router transitions are a quick and easy way t...

MySQL-8.0.26 Configuration Graphics Tutorial

Preface: Recently, the company project changed th...

Sample code for implementing the Olympic rings with pure HTML+CSS

Rendering Code - Take the blue and yellow rings a...

Summary of front-end knowledge in the Gokudō game

background In the early stages of learning Japane...

Implementation of Portals and Error Boundary Handling in React

Table of contents Portals Error Boundary Handling...

js dynamically adds example code for a list of circled numbers

1. Add the ul tag in the body first <!-- Unord...

JS interview question: Can forEach jump out of the loop?

When I was asked this question, I was ignorant an...