Linux::Permissions [2]: Detailed explanation of how file operation permissions are represented! Character representation and octal representation instructions!

Series article description

Preface: This article is the content of the basic Linux operation chapter!
The environment I use is based on Tencent Cloud Server: CentOS 7.6 64bit.


Study set recommendations:



Preface

In the previous content sharing, the author mainly shared the basic instructions about Linux command line operations! Including: 用户账户管理指令, 目录/文件的创建拷贝、移动、删除等指令, 文件内容的条件式查看指令, 日期日历指令, 文件查找 / 文件内容过滤查找等指令, 压缩解压 / 打包解包指令, so far, we have introduced the instructions that can be used at this stage! The other instructions involve subsequent content, so they will be continuously updated according to the progress of content sharing!


Starting from the last article, the author will share content related to permissions under Linux in recent issues! At this point a general understanding is needed: Linux 下一切皆文件!


Note: This article is the prerequisite content for subsequent file permission modifications!


1. Understanding of basic file types and operation permissions

1. Review of basic file types

Note:Linux 下一切皆文件!


The main file types under Linux are as follows (the ones marked in red are the most common file types at this stage):

  • d:目录文件
  • - :普通文件
  • p: pipe file
  • b: block device farm girl [disk]
  • c: character device file [keyboard, monitor]
  • l: soft connection (such as shortcut keys in Windows)
  • s: socket file

Code example (below):

[Mortal@VM-12-16-centos ~]$ ls
Edit_file  install.sh  LinuxCoding  ProjectMake  test  test.c  test_file  T_USERandORDER
[Mortal@VM-12-16-centos ~]$ ll
total 32
drwxrwxr-x 5 Mortal Mortal 4096 Jun 11 17:03 Edit_file
-rw-rw-r-- 1 Mortal Mortal  827 Jun  3 17:00 install.sh
drwxrwxr-x 4 Mortal Mortal 4096 Jun  4 12:09 LinuxCoding
drwxrwxr-x 2 Mortal Mortal 4096 Jun  5 17:18 ProjectMake
drwxrwxr-x 2 Mortal Mortal 4096 Jun  5 20:29 test
-rw-rw-r-- 1 Mortal Mortal   87 Jun  3 17:18 test.c
drwxrwxr-x 2 Mortal Mortal 4096 Jun  5 21:37 test_file
drwxrwxr-x 4 Mortal Mortal 4096 Jun  1 14:58 T_USERandORDER
/* 注意以上文件详细信息中的第一个字符! */

2. Description of file operation permissions

  • File operation permissions include:读、写、执行

  • Note: 不含删除Regarding the deletion issue: it involves the issue of file operation permissions at the upper and lower levels! (In the follow-up: 粘滞位When talking about, we will conduct operational experiments and tests!)


2. How to identify file permissions (two types)

1. Method 1: Character representation

  • 读:r
  • 写:w
  • 执行:x
  • A group of three digits represents a user’s operational permissions! For example: rwx [Indicates that a user has three operations: reading, writing, and executing when operating files!
  • Describing the respective permissions of the three user types requires a total of nine characters!
character representation significance character representation significance
r - - read only - w - Can only be written
r w - Readable and writable - w x Writable and executable
r - x Readable and executable (not writable) - - x Executable only
r w x Readable, writable and executable - - - No permission

2. Method 2: Octal representation

In the character representation, it has been explained that: it can be used 三位为一组表示一个用户的可操作权限!for three operations: reading, writing and executing. Obviously the operation of the representation on each bit is specific! To put it bluntly: it is either readable or unreadable, etc.!


对于只有两种状态的表示方式,我们可以采用:二进制表示法!If a bit is 1, it means it has the specified operation authority on the corresponding bit! 0 means no! Then the list in the previous article can be modified into a table in the following form!

Character (octal) notation significance Character (octal) notation significance
r - - (100) read only - w - (010) Can only be written
r w - (110) Readable and writable (not executable) - w x (011) Writable and executable
r - x (101) Readable and executable (not writable) - - x (011) Executable only
r w x (111) Readable, writable and executable - - - (000) No permission

As shown in the table above, there are eight states. Coincidentally, three-digit binary numbers can be combined into one octal number. Then the rwx three permissions can be expressed in octal as follows:

Permissions character representation binary representation Octal notation
read only r - - 100 4
just write - w - 010 2
Execute only - - x 001 1

Given the above representation, it can be deduced to the following representation:

Permissions character representation binary representation Octal notation
Readable and writable r w - 110 6(4 + 2)
Readable and executable r - x 101 5(4 + 1)
Writable and executable - w x 011 3(2 + 1)
Readable, writable and executable r w x 111 7(4+2+1)
No permission - - - 000 0

As in the table above! As long as you remember that 421 corresponds to rwx, you can directly match various other operation permission states through addition and combination !同时,只用八进制的三个数字即可表示三个用户的文件操作权限状况!


Summarize

This article introduces two ways to express file operation permissions: 字符表示法and 八进制表示法. The next issue will:详解 Linux 下文件权限修改指令 chmod!

Guess you like

Origin blog.csdn.net/weixin_53202576/article/details/131196610