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

MySQL uses frm files and ibd files to restore table data

Table of contents Introduction to frm files and i...

How does Vue3's dynamic components work?

Table of contents 1. Component Registration 1.1 G...

Gearman + MySQL to achieve persistence operation example

This article uses the gearman+mysql method to imp...

Docker sets up port mapping, but cannot access the solution

#docker ps check, all ports are mapped CONTAINER ...

A brief discussion on how to customize the host file in Docker

Table of contents 1. Command 2. docker-compose.ym...

Summary of XHTML application in web design study

<br />Generally speaking, the file organizat...

MySQL 8.0.12 decompression version installation tutorial

This article shares the installation tutorial of ...

Summary of MySql storage engine and index related knowledge

Storage Engine What is a database storage engine?...

Detailed explanation of as, question mark and exclamation mark in Typescript

1. The as keyword indicates an assertion In Types...

Specific steps for Vue browser to return monitoring

Preface When sharing a page, you hope to click th...

JavaScript code to implement a simple calculator

This article example shares the specific code of ...

mysql installer web community 5.7.21.0.msi installation graphic tutorial

This article example shares the specific code for...