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

CSS layout tutorial: How to achieve vertical centering

Preface I have been summarizing my front-end know...

How to configure the pdflatex environment in docker

Technical Background Latex is an indispensable to...

How to ensure transaction characteristics of MySQL InnoDB?

Preface If someone asks you "What are the ch...

Master-slave synchronous replication configuration of MySQL database under Linux

The advantage of the master-slave synchronization...

Service management of source package installation under Linux

Table of contents 1. Startup management of source...

npm Taobao mirror modification explanation

1. Top-level usage 1. Install cnpm npm i -g cnpm ...

How to configure environment variables in Linux environment

JDK download address: http://www.oracle.com/techn...

Using CSS3 to achieve transition and animation effects

Why should we use CSS animation to replace JS ani...

Full HTML of the upload form with image preview

The upload form with image preview function, the ...

Vue implements the frame rate playback of the carousel

This article example shares the specific code of ...

Example of JSON output in HTML format (test interface)

To display the JSON data in a beautiful indented ...