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

Blog    

Recommend

Detailed explanation of tinyMCE usage and experience

Detailed explanation of tinyMCE usage initializat...

MySQL startup error InnoDB: Unable to lock/ibdata1 error

An error message appears when MySQL is started in...

Detailed explanation of command to view log files in Linux environment

Table of contents Preface 1. cat command: 2. more...

How to strike a balance between ease of use and security in the login interface

Whether you are a web designer or a UI designer, ...

Summary of the minesweeping project implemented in JS

This article shares the summary of the JS mineswe...

What are the rules for context in JavaScript functions?

Table of contents 1. Rule 1: Object.Method() 1.1 ...

How to implement property hijacking with JavaScript defineProperty

Table of contents Preface Descriptors Detailed ex...

A simple LED digital clock implementation method in CSS3

This should be something that many people have do...

JavaScript canvas to achieve raindrop effects

This article example shares the specific code of ...

The principles and defects of MySQL full-text indexing

MySQL full-text index is a special index that gen...

CSS Viewport Units for Fast Layout

CSS Viewport units have been around for the past ...

In-depth understanding of JavaScript callback functions

Table of contents Preface Quick Review: JavaScrip...

Summary of Linux nc command

NC's full name is Netcat (Network Knife), and...

Design Story: The Security Guard Who Can't Remember License Plates

<br />In order to manage the vehicles enteri...