I. Users, groups, and permissions

Unix and Linux systems are multi-user and multi-task systems, so such systems have the concept of users and groups, so the same file permissions also have corresponding owning users and owning groups

Mac file attributes

We can see this information when viewing a directory with the ls -l command, from left to right

  • permissionsrRead (read),w(write),x(execute)
  • Number of links
  • The owner of the
  • Subordinate to the group
  • The file size
  • Last modified Date
  • The file name

Just looking at the permissions, this item is divided into four parts, from left to right

  • The file typedDirectory,-(documents)
  • File owner permissions (read, write, and execute permissions from left to right,-Indicates no such permission)
  • Group user permissions (read, write, and execute permissions from left to right.-Indicates no such permission)
  • Non-group user rights (read, write, and execute rights from left to right.-Indicates no such permission)

2.1 Number Types

The comparison table of each authority number: R :4 W :2 x:1, binary means that each authority is represented by displacement operation

  • r: 0100 = 4
  • w: 0010 = 2
  • x: 0001 = 1

If you have all permissions it’s 0111 which is 7 which is RWX, if you have none it’s 0000 which is 0 which is —

If the permission of a file is -rwxr-xr-x

  • This is a file
  • User: 4+2+1=7
  • Group: 4+0+1=5
  • Other: 4+0+1=5

2.2 Symbol Permission

Chmod [u, g, O, a] [+(add), -(Remove), =(set)] [r, w, x] File name

  • u:user(owner)
  • g:group(group user)
  • o: the other (other)
  • a: all (all)

threechmodThe command

Let’s create a new file called test.txt and check its permissions

3.1 practice a

If I want to set file owner permissions to RWX I can do so

A:

chmod u=rwx test.txt
Copy the code

Method 2:

chmod u+rwx test.txt
Copy the code

Three:

chmod 744 test.txt
Copy the code

3.2 exercise two

I want to give the owner of the file the write permission to do that

A:

chmod u-w test.txt
Copy the code

Method 2:

chmod u=rx test.txt
Copy the code

Three:

chmod 544 test.txt
Copy the code

3.3 practice three

I want to grant all permissions to all users (RWX)

chmod 777 test.txt
Copy the code

I want to grant no permissions to all users (–)

chmod 000 test.txt
Copy the code

3.4 Default User

What is the result of my execution??

chmod +x test.txt
Copy the code

Remember, if user A is selected by default, chmod is angry (°▽°) blue ✿