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

Better looking CSS custom styles (title h1 h2 h3)

Rendering Commonly used styles in Blog Garden /*T...

Html to achieve dynamic display of color blocks report effect (example code)

Use HTML color blocks to dynamically display data...

Detailed explanation of Linux zabbix agent deployment and configuration methods

1. Install zabbix-agent on web01 Deploy zabbix wa...

Detailed explanation of invisible indexes in MySQL 8.0

Word MySQL 8.0 has been released for four years s...

Analysis of the project process in idea packaging and uploading to cloud service

one. First of all, you have to package it in idea...

CentOS 7.x deployment of master and slave DNS servers

1. Preparation Example: Two machines: 192.168.219...

Detailed use cases of vue3 teleport

Official Website https://cli.vuejs.org/en/guide/ ...

Implement a simple search engine based on MySQL

Table of contents Implementing a search engine ba...

A brief introduction to React

Table of contents 1. CDN introduction 1.1 react (...

Vue easily realizes watermark effect

Preface: Use watermark effect in vue project, you...

Pros and Cons of Vite and Vue CLI

There is a new build tool in the Vue ecosystem ca...

VMware and CentOS system installation method to reset the root password

Today's Tasks 1. Choice of Linux distribution...