Detailed explanation of viewing and setting file permissions on Mac

Detailed explanation of viewing and setting file permissions on Mac

Preface

To modify file permissions in the terminal of a Mac system, use the chmod command in Linux. This article will introduce you to files and permissions under Unix and Linux. Let’s take a look at the detailed introduction.

Example

# Let's create a test directory first $ mkdir test && cd test
# Create a main.txt file and write some content $ echo hello world >> text.txt
# Create another empty directory $ mkdir js
# View information$ ls -l
total 8
drwxr-xr-x 2 frank staff 64 7 12 20:03 js # This line is the information of the js directory -rw-r--r-- 1 frank staff 13 7 12 19:52 main.txt # This line is the information of main.txt

As shown above, both files and directories have the following information:

# General format of permission information:
-rwxr-xr-x number user group filesize updatetime filename

The general format is divided into 7 parts, namely:

1. File attributes, indicating the file type, read/write/executable permissions, etc., a total of 10 characters;

  • The first character indicates the type, and the following 9 characters are divided into 3 groups, indicating the read/write/executable permissions of the file relative to the current user (user), the group to which the current user belongs (group), and other users (other).
  • rwx: represents permissions, - represents no permissions, r represents read permissions, w represents write permissions, and x represents execute permissions.
  • Take the main.txt above as an example. The first character is -, which indicates the file type. The first character of the js directory is d, which indicates the directory.
  • The next three characters are rw-, which means that the file is readable and writable for the current user, but not executable.
  • The next three characters are r--, which means that the file has read-only permission for members of the group to which the current user belongs, and no write or executable permission.
  • The last three characters are also r--, which means that other users can only read the file but cannot write or execute it.

2. number, which indicates the number of file inodes. Inode indicates the area where the original information of the file is stored.

3. user, indicating the current user name

4. group, indicating the name of the user group to which the current user belongs

5. filesize, indicating the size of the file in bytes

6. updatetime, indicating the last modification time of the file

7. filename, indicating the file name

Modify file permissions

The permissions of main.txt are -rw-r--r-- 1 frank staff 13 7 12 19:52 main.txt, and the permissions for other users are r--, which means they can only read but not write. What if there is a requirement to allow other users to write? At this time, you need to modify the permissions of main.txt so that other users can also perform write operations.

# Command format for modifying permissions $ [sudo] chmod [<permission range><permission operation><specific permissions>] [file or directory]

1. Scope of authority

  • u: user, indicating the owner of the file or directory
  • g: group, indicating the group to which the file or directory belongs
  • o: other, except the file or directory owner or the group to which it belongs, other users belong to this range
  • a: all, that is, all users, including the owner of the file or directory, the group to which it belongs, and other users

2. Permission Operation

  • + indicates adding permissions
  • - means cancel the permission
  • = indicates the only setting permission

3. Specific permissions

  • r means readable
  • w means writable
  • x means executable

Having explained so much, let's now use the command to allow other users to also have write permissions to main.txt:

# Allow other users to have write permissions $ chmod o+w main.txt
# Confirm$ ls -l main.txt
-rw-r--rw- 1 frank staff 13 7 12 19:52 main.txt

# Allow all users to have executable permissions, but not to modify or read $ chmod a+xrw main.txt
# Confirm again---x--x--x 1 frank staff 13 7 12 19:52 main.txt

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Use the chmod command to modify file permissions on Mac

<<:  How to make a List in CocosCreator

>>:  MySQL variable declaration and stored procedure analysis

Recommend

A brief understanding of the relevant locks in MySQL

This article is mainly to take you to quickly und...

Summary of some common uses of refs in React

Table of contents What are Refs 1. String type Re...

How to modify the forgotten password when installing MySQL on Mac

1. Install MySQL database on mac 1. Download MySQ...

Html long text automatically cuts off when it exceeds the tag width

When we display long text, we often need to interc...

MySQL Database Basics: A Summary of Basic Commands

Table of contents 1. Use help information 2. Crea...

The past two years with user experience

<br />It has been no more than two years sin...

htm beginner notes (must read for beginners)

1. What is HTML HTML (HyperText Markup Language):...

Detailed explanation of Shell script control docker container startup order

1. Problems encountered In the process of distrib...

Detailed explanation of HTML page header code example

Knowledge point 1: Set the base URL of the web pa...

Detailed explanation of fs module and Path module methods in Node.js

Overview: The filesystem module is a simple wrapp...

Deeply understand how nginx achieves high performance and scalability

The overall architecture of NGINX is characterize...

Solution to "Specialized key was too long" in MySQL

Table of contents Solution 1 Solution 2 When crea...

Comparison of various ways to measure the performance of JavaScript functions

Table of contents Overview Performance.now Consol...

Measured image HTTP request

Please open the test page in a mainstream browser...