File permissions view and setup details in Mac

  • 2021-01-02 22:08:55
  • OfStack

preface

Modifying file permissions on the end of the Mac system uses the chmod command in Linux. This article will introduce you to files and permissions under Unix and Linux. Without further ado, let's take a look at the details

For example,


#  So let's create 1 Five test directories 
$ mkdir test && cd test
#  create 1 a main.txt File and write 1 Some of the content 
$ echo hello world >> text.txt
#  To create a 1 An empty directory 
$ mkdir js
#  Check the information 
$ ls -l
total 8
drwxr-xr-x 2 frank staff 64 7 12 20:03 js #  This line is js Directory information 
-rw-r--r-- 1 frank staff 13 7 12 19:52 main.txt #  This line is main.txt The information of 

As shown above, 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, which are:

1. File attribute, indicating that the file type is read/write/execute and other permissions, with 10 characters in total;

The first character represents the type, followed by nine characters in three groups, indicating the read/write/executable permissions of the file relative to the current user (user), the current user's group (group), and other users (other). rwx: for permissions, - for no permissions, r for read with read permissions; w represents write with writable permissions; x has executable authority for execute Take main. txt above, for example. The first character is -, indicating a file type; The first character of the js directory is d, indicating the directory directory The next three characters are rw-, indicating that the file is readable and writeable for the current user, but not executable The next three characters are r--, meaning that the file has only read-only permissions for members of the current user's group, and neither write nor execute permissions The last three characters are also r--, meaning that the file is readable, not writable, or executable by other users

2. number represents the number of file inode, and inode represents the area where the original information of the file is stored;

3. user, represents the current user name

4. group, the name of the user group that the current user is in

5, filesize, represents the size of the file, the unit is byte

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

7, filename, represents the file name

Modify file permissions

main.txt's permission is -ES72en-ES73en --r-- 1 frank staff 13 7 12 19:52 main.txt, the permission for other users is r-- that is, can only read and cannot write, what if there is a demand that other users can write? At this point, you need to modify the main.txt permissions so that other users can write as well.


#  Modify the command format for permissions 
$ [sudo] chmod [< competence >< Permission to operate >< Specific privileges >] [ File or directory ]

1. Scope of authority

u: user, representing the owner of the file or directory g: group, representing the group to which the file or directory belongs o: other, except for the file or directory owner or the group to which the user belongs 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 increased permissions - means cancel the permission = means only 1 permission is set

3. Specific authority

r means readable w means writeable x stands for executable

With that said, let's now command main.txt to allow other users to write:


#  Let other users 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

#  Let all users have executable permissions, but not modifiable and unreadable 
$ chmod a+x-r-w main.txt
#  To confirm again 
---x--x--x 1 frank staff 13 7 12 19:52 main.txt

conclusion


Related articles: