【Linux系统】详解Linux权限

文章目录

  • 前言
  • 一、学习Linux权限的铺垫知识
    • 1.Linux的文件分类
    • 2.Linux的用户
      • 2.1 Linux下用户分类
      • 2.2 创建普通用户
      • 2.3 切换用户
      • 2.4 sudo(提升权限的指令)
  • 二、Linux权限的概念以及修改方法
    • 1.权限的概念
    • 2.文件访问权限 和 访问者身份的相关修改(设置)方法
      • 2.1 文件权限属性的8进制数值表示方法
      • 2.2 文件的初始权限 和 umask 指令
      • 2.3 chmod 指令
      • 2.4 chown 指令
      • 2.5 chgrp 指令
  • 三、Linux权限的效果实践
    • 1.普通文件的权限效果
    • 2.目录文件的权限效果
    • 3.文件的权限效果受其所在目录权限的影响
  • 四、粘滞位(常用于合作开发)


前言

一、学习Linux权限的铺垫知识(Linux的文件分类 和 Linux的用户相关知识)
二、Linux权限的概念以及修改方法(文件访问权限 和 访问者身份的相关修改方法)
三、Linux权限的效果实践(普通文件的权限效果 和 目录文件的权限效果)
四、粘滞位(常用于合作开发)


一、学习Linux权限的铺垫知识

1.Linux的文件分类

windows操作系统区分文件类型,是用文件后缀区分的;
Linux操作系统区分文件类型,是以文件的属性列区分的

在这里插入图片描述

文件类型:
◦ d:目录文件(文件夹)
◦ -:普通文件 (例如:源代码、文本文件、可执行程序、音视频、各种文档 和 库文件等)
◦ l:软链接(类似Windows的快捷方式)
◦ b:块设备文件(例如硬盘、光驱等)
◦ p:管道文件
◦ c:字符设备文件(例如屏幕等串口设备)
◦ s:套接口文件

注: 前两种文件类型是常见类型,后面几种文件类型一般都是在特定场景下才会用到(不常用)。故后面只对前两种类型的文件进行权限讨论。

  1. Linux操作系统区分文件类型,是以文件的属性列区分的,更改文件的后缀不会影响文件类型:
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 4
drwxrwxr-x 2 zh zh 4096 Apr 24 15:01 ppt
-rw-rw-r-- 1 zh zh    0 Apr 24 15:00 test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ mv ppt ppt.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 4
drwxrwxr-x 2 zh zh 4096 Apr 24 15:01 ppt.txt
-rw-rw-r-- 1 zh zh    0 Apr 24 15:00 test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ mv test.c test
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 4
drwxrwxr-x 2 zh zh 4096 Apr 24 15:01 ppt.txt
-rw-rw-r-- 1 zh zh    0 Apr 24 15:00 test
  1. 虽然Linux操作系统不以文件后缀区分文件类型,但这并不代表Linux下的工具不使用文件后缀(比如gcc):

两个普通文件 test.c 和 test.txt 中的内容一模一样,只有文件后缀不同。gcc成功编译 test.c 文件,但编译 test.txt 文件直接报错。可以看出gcc工具使用了文件后缀,它只会编译特定后缀的普通文件。

[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 4
-rw-rw-r-- 1 zh zh 73 Apr 24 15:12 test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ cat test.c
#include <stdio.h>int main()
{printf("hello world!\n");return 0;
}
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ gcc test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 16
-rwxrwxr-x 1 zh zh 8360 Apr 24 15:13 a.out
-rw-rw-r-- 1 zh zh   73 Apr 24 15:12 test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ./a.out
hello world!
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 4
-rw-rw-r-- 1 zh zh 73 Apr 24 15:12 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ cat test.txt
#include <stdio.h>int main()
{printf("hello world!\n");return 0;
}
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ gcc test.txt
test.txt: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status

2.Linux的用户

2.1 Linux下用户分类

Linux是一个多用户操作系统。
Linux下的用户分为两类:超级用户(root)和 普通用户。

• 超级用户:可以在linux系统下做任何事情,不受权限限制
• 普通用户:在linux下做有限的事情,受权限限制
( 超级用户的命令行提示符是“#”,普通用户的命令行提示符是“$” )

root用户在安装Linux操作系统时就创建好了,root用户只有一个,而普通用户可以有多个。
(root用户可以创建 和 删除普通用户)

2.2 创建普通用户

每个用户都有对应的家目录,当启动机器时,登录指定用户,他们都会默认从自己的家目录开始。
root用户在安装操作系统的时候,就已经内置了工作目录: /root,这就是root用户的家目录,登录root用户时会默认从这个路径开始。
root用户可以创建普通用户,每次新建⼀个普通用户都会在/home目录下为新用户创建新的工作目录,目录以新用户名称命名。

[zh@iZbp1dr1jtgcuih41mw88oZ d3]$ cd /home
[zh@iZbp1dr1jtgcuih41mw88oZ home]$ ls
ccy  zh

比如我的Linux机器下创建了两个普通用户,ccy 和 zh,那么他们的家目录分别是/home/ccy 和 /home/zh

  1. 铺垫完毕,接下来展示root用户是如何创建普通用户:
    • 第一步(添加新用户) :adduser 用户名(自己取)
    • 第二步(为新用户设置密码):passwd 用户名

    注: Linux下输密码是默认不回显的,为了保护用户隐私)
[root@iZbp1dr1jtgcuih41mw88oZ zh]# adduser lisi
[root@iZbp1dr1jtgcuih41mw88oZ zh]# passwd lisi
Changing password for user lisi.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@iZbp1dr1jtgcuih41mw88oZ zh]# ls /home
ccy  lisi  zh
  1. root用户删除普通用户(userdel -r 用户名):
[root@iZbp1dr1jtgcuih41mw88oZ zh]# ls /home
ccy  lisi  zh
[root@iZbp1dr1jtgcuih41mw88oZ zh]# userdel -r lisi
[root@iZbp1dr1jtgcuih41mw88oZ zh]# ls /home
ccy  zh

2.3 切换用户

切换用户的两种方法:

语法:su 用户名
功能:切换到指定用户(切换到root用户时,root可省略),不会更改当前工作目录

语法:su - 用户名
功能:切换到指定用户(切换到root用户时,root可省略),将工作目录切换到指定用户的家目录

注: root用户切换到普通用户不用输密码;普通用户切换到root用户 或 其他普通用户都要输对应密码。

  1. su 用户名:切换到指定用户(切换到root用户时,root可省略),不会更改当前工作目录
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ whoami
zh
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ pwd
/home/zh/ppt
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ su
Password: 
[root@iZbp1dr1jtgcuih41mw88oZ ppt]# whoami
root
[root@iZbp1dr1jtgcuih41mw88oZ ppt]# pwd
/home/zh/ppt
[root@iZbp1dr1jtgcuih41mw88oZ ppt]# su zh
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ whoami
zh
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ pwd
/home/zh/ppt
  1. su - 用户名:切换到指定用户(切换到root用户时,root可省略),将工作目录切换到指定用户的家目录
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ whoami
zh
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ pwd
/home/zh/ppt
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ su -
Password: 
Last login: Thu Apr 24 16:39:36 CST 2025 on pts/0
[root@iZbp1dr1jtgcuih41mw88oZ ~]# whoami
root
[root@iZbp1dr1jtgcuih41mw88oZ ~]# pwd
/root
[root@iZbp1dr1jtgcuih41mw88oZ ~]# su - zh
Last login: Thu Apr 24 16:42:54 CST 2025 on pts/0
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ whoami
zh
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ pwd
/home/zh

2.4 sudo(提升权限的指令)

sudo(superuser do)是Linux系统中用于普通用户临时提升权限的指令,允许普通用户以root权限执行单条命令。(该机制需通过修改/etc/sudoers配置文件实现)

  1. 普通用户 zh 想将 test.txt文件 复制到 /usr路径下,但是这个操作没有被允许,因为权限不够:
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ cp test.txt /usr
cp: cannot create regular file ‘/usr/test.txt’: Permission denied

权限不够,那我们就尝试使用 sudo 指令来提升普通用户的权限,但是 sudo 执行这条命令依然没有成功,原因是:zh is not in the sudoers file(该用户没有在sudoers file文件中,这个文件实际就是/etc/sudoers配置文件)

[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ sudo cp test.txt /usrWe trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:#1) Respect the privacy of others.#2) Think before you type.#3) With great power comes great responsibility.[sudo] password for zh: 
zh is not in the sudoers file.  This incident will be reported.
  1. 普通用户要想使用sudo指令提升权限,需要使用root用户修改/etc/sudoers配置文件,root用户是管理员,修改该配置文件将普通用户加入,就相当于将该普通用户放进白名单。 修改该配置文件的过程如下:

第一步:在root用户下,打开/etc/sudoers配置文件(通过nano编辑器)。跳转到100行左右位置找到下图圈出的内容

[root@iZbp1dr1jtgcuih41mw88oZ zh]# nano /etc/sudoers

在这里插入图片描述
第二步:将普通用户zh加入该配置文件。模仿第一行root用户的写法,另起一行,输入zh后按tab键,再输入ALL=(ALL),再按tab键,最后输入ALL。配置完毕,保存退出。
在这里插入图片描述

  1. 将普通用户zh加入到/etc/sudoers配置文件后。再使用 sudo 提权执行这条命令就成功了。
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ sudo cp test.txt /usr
[sudo] password for zh: 
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l /usr/test.txt
-rw-r--r-- 1 root root 0 Apr 24 19:05 /usr/test.txt

二、Linux权限的概念以及修改方法

1.权限的概念

权限 = 用户身份 + 文件的权限属性

  1. 文件访问者身份的分类:

• 文件的所有者:u—User
• 文件的所属组(组中用户大于等于1人):g—Group
• 其它用户(除所有者 和 所属组中用户外的用户):o—Others
(注:用户初创建文件时,文件的所属组默认只有你自己)

其它用户在文件信息中不会显示,因为它也无需显示,只要知道文件的所有者 和 所属组的信息也就知道了其它用户的信息(其它用户是除所有者 和 所属组中用户外的所有用户)

  1. 权限属性的分类:

• 读(r/4):Read对普通文件而言,具有读取文件内容的权限;对目录来说,具有浏览该目录下文件信息的权限
• 写(w/2):Write对普通文件而言,具有修改文件内容的权限;对目录来说具有删除、新增 和 移动目录内文件的权限
• 执行(x/1):execute对普通文件而言,具有执行文件的权限;对目录来说,具有进入目录的权限
• “—”:表示不具有该项权限

在这里插入图片描述
文件的权限属性有9列,文件访问者身份有3种,正好每种身份对应3列权限属性。(文件的所有者对应前3列,文件的所属组对应中间3列,其它用户对应最后3列)

2.文件访问权限 和 访问者身份的相关修改(设置)方法

2.1 文件权限属性的8进制数值表示方法

-rw-r--r-- 1 root root 0 Apr 24 19:05 /usr/test.txt

rw-r- -r- -对应110100100 转换成8进制:644

-rw-rw-r-- 1 zh zh    0 Apr 24 18:45 test.txt

rw-rw-r- -对应110110100 转换成8进制:664

-rwxr-xr-x  1 root root     62688 Nov  1  2021 ar

rwxr-xr-x对应111101101 转换成8进制:755

drwxrwxr-x 2 zh zh 4096 Apr 24 16:39 ppt

rwxrwxr-x对应111111101 转换成8进制:775

2.2 文件的初始权限 和 umask 指令

umask 指令的介绍:

使用格式:
(1)查看文件掩码:umask
(2)修改文件掩码:umask 新的文件掩码值
功能:
• 查看或修改文件掩码
• 新建普通文件的默认权限=666
• 新建目录的默认权限=777
• 但实际上你所创建的文件和目录,看到的权限往往不是上面这个值。原因就是创建文件或目录的时候还要受到umask的影响。假设默认权限是mask,则实际创建的出来的文件权限是: mask&(~umask)
说明: 超级用户默认掩码值为0022,普通用户默认为0002。(计算文件权限时忽略文件掩码的第一位)

  1. 得到新建文件起始权限的计算过程

新建普通文件的默认权限=666 ,新建目录的默认权限=777
但实际上你所创建的文件和目录,看到的权限往往不是上面这个值。原因就是创建文件或目录的时候还要受到umask的影响。假设默认权限是mask,则实际创建的出来的文件权限是: mask&(~umask)
普通用户的权限掩码默认为0002 (计算文件权限时忽略文件掩码的第一位,也就是把0002当成002)

要转换为2进制计算:权限掩码002的2进制为000 000 010,对权限掩码取反~得 111 111 101
新建普通文件的默认权限 = 666 转换为2进制为 110 110 110
新建普通文件的起始权限 = 110 110 110 & 111 111 101 = 110 110 100,也就是 rw-rw-r- -
新建目录的默认权限 = 777 转换为2进制为 111 111 111
新建目录的起始权限 = 111 111 111 & 111 111 101 = 111 111 101,也就是 rwxrwxr-x

[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ umask
0002
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ touch test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ mkdir ppt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 4
drwxrwxr-x 2 zh zh 4096 Apr 24 21:14 ppt
-rw-rw-r-- 1 zh zh    0 Apr 24 21:13 test.txt
  1. 修改文件掩码会影响文件的起始权限
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ umask 0000
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ umask
0000
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ touch test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ mkdir ppt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 4
drwxrwxrwx 2 zh zh 4096 Apr 24 21:37 ppt
-rw-rw-rw- 1 zh zh    0 Apr 24 21:36 test.txt

2.3 chmod 指令

使用格式:
(1)chmod u/g/o[+/-/=]rwx 文件名
(同时修改多个身份对应的权限要用" , "隔开)
(2)chmod a[+/-/=]rwx 文件名
(3)chmod 8进制权限写法 文件名
功能: 设置文件的访问权限
说明: 只有文件的拥有者和root才可以改变文件的权限
用户符号:
◦ u:所有者
◦ g:所属组
◦ o:其它用户
◦ a:所有用户

  1. chmod u/g/o[+/-/=]rwx 文件名

(1)chmod u/g/o+rwx 文件名

[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-r--r--r-- 1 zh zh 0 Apr 24 21:36 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ chmod u+w test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-rw-r--r-- 1 zh zh 0 Apr 24 21:36 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ chmod g+w test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-rw-rw-r-- 1 zh zh 0 Apr 24 21:36 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ chmod o+w test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-rw-rw-rw- 1 zh zh 0 Apr 24 21:36 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ chmod u+x,g+x,o+x test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-rwxrwxrwx 1 zh zh 0 Apr 24 21:36 test.txt

(2)chmod u/g/o-rwx 文件名

[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-rwxrwxrwx 1 zh zh 0 Apr 24 21:36 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ chmod u-rx,g-wx,o-x test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
--w-r--rw- 1 zh zh 0 Apr 24 21:36 test.txt

(3)chmod u/g/o=rwx 文件名

[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
--w-r--rw- 1 zh zh 0 Apr 24 21:36 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ chmod u=rwx,g=rwx,o=rwx test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-rwxrwxrwx 1 zh zh 0 Apr 24 21:36 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ chmod u=r,g=w,o=x test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-r---w---x 1 zh zh 0 Apr 24 21:36 test.txt
  1. chmod a[+/-/=]rwx 文件名
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-rwxrwxrwx 1 zh zh 0 Apr 24 21:36 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ chmod a-wx test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-r--r--r-- 1 zh zh 0 Apr 24 21:36 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ chmod a+x test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-r-xr-xr-x 1 zh zh 0 Apr 24 21:36 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ chmod a=w test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
--w--w--w- 1 zh zh 0 Apr 24 21:36 test.txt
  1. chmod 8进制权限写法 文件名
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
--w--w--w- 1 zh zh 0 Apr 24 21:36 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ chmod 777 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-rwxrwxrwx 1 zh zh 0 Apr 24 21:36 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ chmod 111 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
---x--x--x 1 zh zh 0 Apr 24 21:36 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ chmod 614 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-rw---xr-- 1 zh zh 0 Apr 24 21:36 test.txt

2.4 chown 指令

格式:
(1)chown 新所有者名 文件名
(2)chown 新所有者名:新所属组名 文件名
功能: 可以修改文件的所有者,也可以同时修改文件的所有者和所属组(需要root权限)
说明: 新所有者名和新所属组名必须是已存在的

  1. chown 新所有者名 文件名(修改文件的所有者)
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-rw---xr-- 1 zh zh 0 Apr 24 21:36 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ sudo chown ccy test.txt
[sudo] password for zh: 
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-rw---xr-- 1 ccy zh 0 Apr 24 21:36 test.txt
  1. chown 新所有者名:新所属组名 文件名(同时修改文件的所有者和所属组)
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-rw---xr-- 1 ccy ccy 0 Apr 24 21:36 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ sudo chown zh:zh test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-rw---xr-- 1 zh zh 0 Apr 24 21:36 test.txt

2.5 chgrp 指令

格式: chgrp 新所属组名 文件名
功能: 修改文件的所属组(需要root权限)
说明: 新所属组名必须是已存在的

[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-rw---xr-- 1 ccy zh 0 Apr 24 21:36 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ sudo chgrp ccy test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ~]$ ls -l
total 0
-rw---xr-- 1 ccy ccy 0 Apr 24 21:36 test.txt

三、Linux权限的效果实践

1.普通文件的权限效果

• 读(r/4):read对普通文件而言,具有读取文件内容的权限
• 写(w/2):write对普通文件而言,具有修改文件内容的权限
• 执行(x/1):execute对普通文件而言,具有执行文件的权限
• “—”:表示不具有该项权限

  1. w 对普通文件而言,具有修改文件内容的权限;r 对普通文件而言,具有读取文件内容的权限

test.txt 文件 的所有者具有rw权限,所属组具有r权限,其它用户没有任何权限。
zh用户属于该文件的所有者,所以他具有读取文件内容和修改文件内容的权限;
ccy用户属于该文件的所属组,所以他具有读取文件内容的权限;
lihua用户属于该文件的其它用户,所以他不具备任何操作该文件的权限

[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ ls -l
total 4
-rw-r----- 1 zh ccy 12 Apr 25 19:03 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ echo "hello world" > test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ cat test.txt
hello world
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ su ccy
Password: 
[ccy@iZbp1dr1jtgcuih41mw88oZ ppt]$ echo "one piece" > test.txt
bash: test.txt: Permission denied
[ccy@iZbp1dr1jtgcuih41mw88oZ ppt]$ cat test.txt
hello world
[ccy@iZbp1dr1jtgcuih41mw88oZ ppt]$ su lihua
Password: 
[lihua@iZbp1dr1jtgcuih41mw88oZ ppt]$ echo "one piece" > test.txt
bash: test.txt: Permission denied
[lihua@iZbp1dr1jtgcuih41mw88oZ ppt]$ cat test.txt
cat: test.txt: Permission denied

// Permission denied 代表权限不够,操作不被允许

  1. 一个可执行文件 = 可执行权限 + 可执行能力
    (一个文件具备可执行权限并不代表这个文件能执行)

(1)gcc 编译 test.c 文件生成了可执行文件 a.out,紧接着执行 a.out,执行成功;
我们删去了 a.out文件的x权限,然后再次执行 a.out,执行失败(a.out文件具备可执行能力,但不具备可执行权限)

[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ ls -l
total 4
-rw-rw-r-- 1 zh zh 69 Apr 25 20:14 test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ cat test.c
#include <stdio.h>
int main()
{printf("one piece\n");return 0;
}
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ gcc test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ ls -l
total 16
-rwxrwxr-x 1 zh zh 8360 Apr 25 20:14 a.out
-rw-rw-r-- 1 zh zh   69 Apr 25 20:14 test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ ./a.out
one piece
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ chmod u-x a.out
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ ls -l
total 16
-rw-rwxr-x 1 zh zh 8360 Apr 25 20:14 a.out
-rw-rw-r-- 1 zh zh   69 Apr 25 20:14 test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ ./a.out
bash: ./a.out: Permission denied

(2)test.c 文件是一个未经过编译的普通c文件,它不具备可执行能力,即使我们赋予它可执行权限,它也依旧不能被执行(test.c 文件具备可执行权限,但不具备可执行能力)

[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ ls -l
total 4
-rw-rw-r-- 1 zh zh 69 Apr 25 20:14 test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ chmod u+x test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ ls -l
total 4
-rwxrw-r-- 1 zh zh 69 Apr 25 20:14 test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ ./test.c
./test.c: line 2: syntax error near unexpected token `('
./test.c: line 2: `int main()'

2.目录文件的权限效果

• 读(r/4):read对目录来说,具有浏览该目录下文件信息的权限
• 写(w/2):write对目录来说,具有删除、新增 和 移动目录下文件 以及 修改目录下文件的文件名的权限
• 执行(x/1):execute对目录来说,具有进入目录的权限
• “—”:表示不具有该项权限

注: 对目录来说,x 权限是 r 和 w 权限的前提,不具备 x 权限,即使有 rw 权限也没有任何效果。

  1. r 对目录来说,具有浏览该目录下文件信息的权限;w 对目录来说,具有删除、新增 和 移动目录下文件 以及 修改目录下文件的文件名的权限

ppt目录 的所有者具有rwx权限,所属组具有rx权限,其它用户具有x权限。
zh用户属于该目录的所有者,所以他具有进入目录、浏览该目录下文件信息 以及 具有删除、新增 和 移动目录下文件 的权限;
ccy用户属于该目录的所属组,所以他具有进入目录、浏览该目录下文件信息 的权限;
lihua用户属于该目录的其它用户,所以他只具有进入目录的权限

[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ ls -l
total 4
drwxr-x--x 3 zh ccy 4096 Apr 25 21:23 ppt
[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ ls -l ppt
total 8
drwxrwxr-x 2 zh zh 4096 Apr 25 20:55 ggb
-rw-rw-r-- 1 zh zh    0 Apr 25 20:55 hello.txt
-rw-rw-r-- 1 zh zh   69 Apr 25 20:14 test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ rm ppt/hello.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ ls -l ppt
total 8
drwxrwxr-x 2 zh zh 4096 Apr 25 20:55 ggb
-rw-rw-r-- 1 zh zh   69 Apr 25 20:14 test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ touch ppt/dwg
[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ ls -l ppt
total 8
-rw-rw-r-- 1 zh zh    0 Apr 25 21:30 dwg
drwxrwxr-x 2 zh zh 4096 Apr 25 20:55 ggb
-rw-rw-r-- 1 zh zh   69 Apr 25 20:14 test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ mv ppt/dwg ppt/abc.txt
[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ ls -l ppt
total 8
-rw-rw-r-- 1 zh zh    0 Apr 25 21:32 abc.txt
drwxrwxr-x 2 zh zh 4096 Apr 25 20:55 ggb
-rw-rw-r-- 1 zh zh   69 Apr 25 20:14 test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ su ccy
Password: 
[ccy@iZbp1dr1jtgcuih41mw88oZ ufc]$ ls -l
total 4
drwxr-x--x 3 zh ccy 4096 Apr 25 21:32 ppt
[ccy@iZbp1dr1jtgcuih41mw88oZ ufc]$ ls -l ppt
total 8
-rw-rw-r-- 1 zh zh    0 Apr 25 21:32 abc.txt
drwxrwxr-x 2 zh zh 4096 Apr 25 20:55 ggb
-rw-rw-r-- 1 zh zh   69 Apr 25 20:14 test.c
[ccy@iZbp1dr1jtgcuih41mw88oZ ufc]$ rm ppt/abc.txt
rm: remove write-protected regular empty file ‘ppt/abc.txt’? y
rm: cannot remove ‘ppt/abc.txt’: Permission denied
[ccy@iZbp1dr1jtgcuih41mw88oZ ufc]$ touch ppt/one.txt
touch: cannot touch ‘ppt/one.txt’: Permission denied
[ccy@iZbp1dr1jtgcuih41mw88oZ ufc]$ su lihua
Password: 
[lihua@iZbp1dr1jtgcuih41mw88oZ ufc]$ ls -l
total 4
drwxr-x--x 3 zh ccy 4096 Apr 25 21:32 ppt
[lihua@iZbp1dr1jtgcuih41mw88oZ ufc]$ ls -l ppt
ls: cannot open directory ppt: Permission denied
[lihua@iZbp1dr1jtgcuih41mw88oZ ufc]$ touch ppt/one.txt
touch: cannot touch ‘ppt/one.txt’: Permission denied
[lihua@iZbp1dr1jtgcuih41mw88oZ ufc]$ cd ppt
[lihua@iZbp1dr1jtgcuih41mw88oZ ppt]$ pwd
/home/zh/ufc/ppt
  1. 对目录来说,x 权限是 r 和 w 权限的前提,不具备 x 权限,即使有 rw 权限也没有任何效果
[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ ls -l
total 4
drw-rw-rw- 3 zh ccy 4096 Apr 25 21:32 ppt
[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ ls -l ppt
ls: cannot access ppt/ggb: Permission denied
ls: cannot access ppt/abc.txt: Permission denied
ls: cannot access ppt/test.c: Permission denied
total 0
-????????? ? ? ? ?            ? abc.txt
d????????? ? ? ? ?            ? ggb
-????????? ? ? ? ?            ? test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ rm ppt/abc.txt
rm: cannot remove ‘ppt/abc.txt’: Permission denied
[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ touch ppt/one.txt
touch: cannot touch ‘ppt/one.txt’: Permission denied

3.文件的权限效果受其所在目录权限的影响

  1. ccy用户没有进入ppt目录的权限(我们是使用zh用户进入ppt目录,再切成ccy用户),
    所以即使ppt目录中的 ggb目录 和 test.c文件 给了ccy用户所有权限,但是ccy用户仍然不能对这两个文件进行任何操作。因为ccy用户连进入ppt目录的权限都没有,所以不具备操作其下文件的资格。
[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ ls -l
total 4
drwx------ 3 zh zh 4096 Apr 25 22:21 ppt
[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ cd ppt
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ ls -l
total 8
drwxrwxrwx 3 ccy ccy 4096 Apr 25 22:03 ggb
-rwxrwxrwx 1 ccy ccy   12 Apr 25 22:24 test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ppt]$ su ccy 
Password: 
[ccy@iZbp1dr1jtgcuih41mw88oZ ppt]$ echo "hello world" > test.c
bash: test.c: Permission denied
[ccy@iZbp1dr1jtgcuih41mw88oZ ppt]$ cat test.c
cat: test.c: Permission denied
[ccy@iZbp1dr1jtgcuih41mw88oZ ppt]$ ls -l ggb
ls: cannot access ggb: Permission denied
[ccy@iZbp1dr1jtgcuih41mw88oZ ppt]$ touch ggd/kfc.txt
touch: cannot touch ‘ggd/kfc.txt’: Permission denied
[ccy@iZbp1dr1jtgcuih41mw88oZ ppt]$ cd ggb
bash: cd: ggb: Permission denied
  1. ccy用户具有进入ppt的权限,就可以正常操作其下文件
[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ ls -l
total 4
drwx--x--x 3 zh zh 4096 Apr 25 22:21 ppt
[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ ls -l ppt
total 8
drwxrwxrwx 3 ccy ccy 4096 Apr 25 22:03 ggb
-rwxrwxrwx 1 ccy ccy   12 Apr 25 22:24 test.c
[zh@iZbp1dr1jtgcuih41mw88oZ ufc]$ su ccy
Password: 
[ccy@iZbp1dr1jtgcuih41mw88oZ ufc]$ cd ppt
[ccy@iZbp1dr1jtgcuih41mw88oZ ppt]$ echo "hello world" > test.c
[ccy@iZbp1dr1jtgcuih41mw88oZ ppt]$ cat test.c
hello world
[ccy@iZbp1dr1jtgcuih41mw88oZ ppt]$ ls -l ggb
total 4
drwxrwxr-x 2 zh zh 4096 Apr 25 22:03 lgd
[ccy@iZbp1dr1jtgcuih41mw88oZ ppt]$ touch ggb/kfc.txt
[ccy@iZbp1dr1jtgcuih41mw88oZ ppt]$ cd ggb
[ccy@iZbp1dr1jtgcuih41mw88oZ ggb]$ pwd
/home/zh/ufc/ppt/ggb

四、粘滞位(常用于合作开发)

普通用户的家目录只允许自己和root用户进入;root用户的家目录只允许root用户进入。所以多名普通用户要进行合作开发的话,一般不会在家目录下进行。

[root@iZbp1dr1jtgcuih41mw88oZ home]# pwd
/home
[root@iZbp1dr1jtgcuih41mw88oZ home]# ls -l
total 12
drwx------ 2 ccy   ccy   4096 Apr 10 21:03 ccy
drwx------ 2 lihua lihua 4096 Apr 25 23:14 lihua
drwx------ 3 zh    zh    4096 Apr 25 21:03 zh
[root@iZbp1dr1jtgcuih41mw88oZ /]# ls -ld root
dr-xr-x---. 6 root root 4096 Apr 14 11:02 root

想要实现多名用户合作开发(数据共享),一般会用root用户在家目录外创建一个公共的目录,给其他用户身份放开权限(rwx),让多名普通用户以其他用户身份在公共的目录下实现合作开发:

[root@iZbp1dr1jtgcuih41mw88oZ /]# mkdir teamwork
[root@iZbp1dr1jtgcuih41mw88oZ /]# ls -ld teamwork
drwxr-xr-x 2 root root 4096 Apr 27 17:10 teamwork
[root@iZbp1dr1jtgcuih41mw88oZ /]# chmod 757 teamwork
[root@iZbp1dr1jtgcuih41mw88oZ /]# ls -ld teamwork
drwxr-xrwx 2 root root 4096 Apr 27 17:10 teamwork

多名普通用户以其他用户身份在公共的目录 /teamwork 进行数据共享:

[zh@iZbp1dr1jtgcuih41mw88oZ /]$ cd teamwork
[zh@iZbp1dr1jtgcuih41mw88oZ teamwork]$ touch test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ teamwork]$ mkdir ppt
[zh@iZbp1dr1jtgcuih41mw88oZ teamwork]$ ls -l
total 4
drwxrwxr-x 2 zh zh 4096 Apr 27 17:15 ppt
-rw-rw-r-- 1 zh zh    0 Apr 27 17:15 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ teamwork]$ echo "hello world" > test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ teamwork]$ cat test.txt
hello world
[ccy@iZbp1dr1jtgcuih41mw88oZ /]$ cd teamwork
[ccy@iZbp1dr1jtgcuih41mw88oZ teamwork]$ ls -l
total 8
drwxrwxr-x 2 zh zh 4096 Apr 27 17:15 ppt
-rw-rw-r-- 1 zh zh   12 Apr 27 17:17 test.txt
[ccy@iZbp1dr1jtgcuih41mw88oZ teamwork]$ touch d1.txt
[ccy@iZbp1dr1jtgcuih41mw88oZ teamwork]$ ls -l
total 8
-rw-rw-r-- 1 ccy ccy    0 Apr 27 17:19 d1.txt
drwxrwxr-x 2 zh  zh  4096 Apr 27 17:15 ppt
-rw-rw-r-- 1 zh  zh    12 Apr 27 17:17 test.txt
[ccy@iZbp1dr1jtgcuih41mw88oZ teamwork]$ echo "one piece" > d1.txt
[ccy@iZbp1dr1jtgcuih41mw88oZ teamwork]$ cat d1.txt
one piece
[ccy@iZbp1dr1jtgcuih41mw88oZ teamwork]$ cat test.txt
hello world
[lihua@iZbp1dr1jtgcuih41mw88oZ /]$ cd teamwork
[lihua@iZbp1dr1jtgcuih41mw88oZ teamwork]$ ls -l
total 12
-rw-rw-r-- 1 ccy ccy   10 Apr 27 17:20 d1.txt
drwxrwxr-x 2 zh  zh  4096 Apr 27 17:15 ppt
-rw-rw-r-- 1 zh  zh    12 Apr 27 17:17 test.txt
[lihua@iZbp1dr1jtgcuih41mw88oZ teamwork]$ cat d1.txt
one piece
[lihua@iZbp1dr1jtgcuih41mw88oZ teamwork]$ cat test.txt
hello world

以上可以看出多名普通用户确实在root用户创建的公共目录/teamwork下实现了数据共享。但其实还存在一些问题,那就是在这个目录下普通用户权限过大,他们可以直接删除其他人创建的文件,如下:

[lihua@iZbp1dr1jtgcuih41mw88oZ /]$ cd teamwork
[lihua@iZbp1dr1jtgcuih41mw88oZ teamwork]$ ls -l
total 12
-rw-rw-r-- 1 ccy ccy   10 Apr 27 17:20 d1.txt
drwxrwxr-x 2 zh  zh  4096 Apr 27 17:15 ppt
-rw-rw-r-- 1 zh  zh    12 Apr 27 17:17 test.txt
[lihua@iZbp1dr1jtgcuih41mw88oZ teamwork]$ rm d1.txt
rm: remove write-protected regular file ‘d1.txt’? y
[lihua@iZbp1dr1jtgcuih41mw88oZ teamwork]$ rm -r ppt
rm: remove write-protected directory ‘ppt’? y
[lihua@iZbp1dr1jtgcuih41mw88oZ teamwork]$ ls -l
total 4
-rw-rw-r-- 1 zh zh 12 Apr 27 17:17 test.txt

合作开发是为了多名普通用户之间实现数据共享,但是却不希望自己创建的文件被其他人直接删除,为了限制合作开发下普通用户的权限,引入了 “粘滞位” 的用法。当一个目录被设置为 “粘滞位” (用chmod +t),则该目录下的文件只能由:

(1)root用户删除
(2)该目录的所有者(合作开发中一般就是root用户)删除
(3)该文件的所有者删除

给 /teamwork 目录设置为"粘滞位"(用chmod +t):

[root@iZbp1dr1jtgcuih41mw88oZ /]# chmod +t teamwork
[root@iZbp1dr1jtgcuih41mw88oZ /]# ls -ld teamwork
drwxr-xrwt 2 root root 4096 Apr 27 19:24 teamwork

效果展示(普通用户zh不能删除其他普通用户创建的文件,只能删除自己创建的文件):

[zh@iZbp1dr1jtgcuih41mw88oZ /]$ cd teamwork
[zh@iZbp1dr1jtgcuih41mw88oZ teamwork]$ ls -l
total 4
-rw-rw-r-- 1 lihua lihua  0 Apr 27 19:24 hello.txt
-rw-rw-r-- 1 zh    zh    12 Apr 27 17:17 test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ teamwork]$ rm hello.txt
rm: remove write-protected regular empty file ‘hello.txt’? y
rm: cannot remove ‘hello.txt’: Operation not permitted
[zh@iZbp1dr1jtgcuih41mw88oZ teamwork]$ rm test.txt
[zh@iZbp1dr1jtgcuih41mw88oZ teamwork]$ ls -l
total 0
-rw-rw-r-- 1 lihua lihua 0 Apr 27 19:24 hello.txt

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/903207.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

路由器的基础配置全解析:静态动态路由 + 华为 ENSP 命令大全

&#x1f680; 路由器的基础配置全解析&#xff1a;静态&动态路由 华为 ENSP 命令大全 &#x1f310; 路由器的基本概念&#x1f4cd; 静态路由配置&#x1f4e1; 动态路由协议&#xff1a;RIP、OSPF、BGP&#x1f5a5; 华为 ENSP 路由器命令大全&#x1f539; 路由器基本…

详细图解 Path-SAM2: Transfer SAM2 for digital pathology semantic segmentation

✨ 背景动机 数字病理中的语义分割&#xff08;semantic segmentation&#xff09;是非常关键的&#xff0c;比如肿瘤检测、组织分类等。SAM&#xff08;Segment Anything Model&#xff09;推动了通用分割的发展&#xff0c;但在病理图像上表现一般。 病理图像&#xff08;Pa…

初识Redis · 哨兵机制

目录 前言&#xff1a; 引入哨兵 模拟哨兵机制 配置docker环境 基于docker环境搭建哨兵环境 对比三种配置文件 编排主从节点和sentinel 主从节点 sentinel 模拟哨兵 前言&#xff1a; 在前文我们介绍了Redis的主从复制有一个最大的缺点就是&#xff0c;主节点挂了之…

HTTP header Cookie 和 Set-Cookie

RFC 6265: HTTP State Management Mechanismhttps://www.rfc-editor.org/rfc/rfc6265 Set-Cookie 响应头 服务器使用 Set-Cookie 响应头向客户端&#xff08;通常是浏览器&#xff09;发送 Cookie。 基本格式&#xff1a; Set-Cookie: <cookie名称><cookie值>;…

【Unity完整游戏开发案例】从0做一个太空大战游戏

1.实现飞机移动控制 // 这个脚本实现控制飞机前后移动&#xff0c;方向由鼠标控制 //1.WS控制前后移动2.鼠标控制上下左右旋转3.AD控制倾斜 using System.Collections; using System.Collections.Generic; using UnityEngine;public class PlayerController : MonoBehav…

【C++】C++11新特性(一)

文章目录 列表初始化initializer_list左值引用和右值引用 列表初始化 在 C98 中可以使用{}对数组或者结构体元素进行统一的列表初始值设定 struct Point {int _x;int _y; }; int main() {int array1[] { 1, 2, 3, 4, 5 };int array2[5] { 0 };Point p { 1, 2 };return 0; …

小黑享受思考心流: 73. 矩阵置零

小黑代码 class Solution:def setZeroes(self, matrix: List[List[int]]) -> None:"""Do not return anything, modify matrix in-place instead."""items []m len(matrix)n len(matrix[0])for i in range(m):for j in range(n):if not m…

精益数据分析(19/126):走出数据误区,拥抱创业愿景

精益数据分析&#xff08;19/126&#xff09;&#xff1a;走出数据误区&#xff0c;拥抱创业愿景 在创业与数据分析的探索之旅中&#xff0c;我们都渴望获取更多知识&#xff0c;少走弯路。今天&#xff0c;我依然带着和大家共同进步的想法&#xff0c;深入解读《精益数据分析…

循环神经网络RNN---LSTM

一、 RNN介绍 循环神经网络&#xff08;Recurrent Neural Network&#xff0c;简称 RNN&#xff09;是一种专门用于处理序列数据的神经网络&#xff0c;在自然语言处理、语音识别、时间序列预测等领域有广泛应用。 传统神经网络 无法训练出具有顺序的数据。模型搭建时没有考…

优考试V4.20机构版【附百度网盘链接】

优考试局域网考试系统具有强大的统计分析功能。优考试通过对考试数据进行统计分析&#xff0c;诸如考试分数分布&#xff0c;考试用时分布&#xff0c;错排行等&#xff0c;让你从整体上了解你的学员&#xff08;员工&#xff09;状态&#xff0c; 同时你也可以对学员&#xff…

【Amazing晶焱科技高速 CAN Bus 传输与 TVS/ESD/EOS 保护,将是车用电子的生死关键无标题】

台北国际车用电子展是亚洲地区重量级的车用电子科技盛会&#xff0c;聚焦于 ADAS、电动车动力系统、智慧座舱、人机界面、车联网等领域。各大车厂与 Tier 1 供应链无不摩拳擦掌&#xff0c;推出最新技术与创新解决方案。 而今年&#xff0c;“智慧座舱” 无疑将成为全场焦点&am…

面试:结构体默认是对齐的嘛?如何禁止对齐?

是的。 结构体默认是对齐的‌。结构体对齐是为了优化内存访问速度和减少CPU访问内存时的延迟。结构体对齐的规则如下&#xff1a; 某数据类型的变量存放的地址需要按有效对齐字节剩下的字节数可以被该数据类型所占字节数整除&#xff0c;char可以放在任意位置&#xff0c;int存…

如何优雅地解决AI生成内容粘贴到Word排版混乱的问题?

随着AI工具的广泛应用&#xff0c;越来越多人开始使用AI辅助撰写论文、报告或博客。然而&#xff0c;当我们直接将AI生成的文本复制到Word文档中时&#xff0c;常常会遇到排版混乱、格式异常的问题。这是因为大部分AI输出时默认使用了Markdown格式&#xff0c;而Word对Markdown…

Golang | HashMap实现原理

HashMap是一种基于哈希表实现的键值对存储结构&#xff0c;它通过哈希函数将键映射到数组的索引位置&#xff0c;支持高效的插入、查找和删除操作。其核心原理如下&#xff1a; 哈希函数&#xff1a;将键转换为数组索引。理想情况下&#xff0c;不同键应映射到不同索引&#xf…

vue3学习之防抖和节流

​ 在前端开发中&#xff0c;我们经常会遇到这样的情况&#xff1a;某些事件&#xff08;如滚动、输入、点击等&#xff09;会频繁触发&#xff0c;如果不加以控制&#xff0c;可能会导致性能问题。Vue3 中的防抖&#xff08;Debounce&#xff09;和节流&#xff08;Throttle&a…

4.2.2 MySQL索引原理以及SQL优化

文章目录 4.2.2 MySQL索引原理以及SQL优化1. 索引与约束1. 索引是什么2. 索引的目的3. 几种索引4. 约束1.外键2. 约束 vs 索引的区别 5. 索引实现1. 索引存储2. 页3. B树4. B树层高问题5. 自增id6. 聚集索引7. 辅助索引 8. innnodb体系结构1. buffer pool2. change buffer 9. 最…

【学习笔记】文件包含漏洞--本地远程包含、伪协议、加密编码

一、文件包含漏洞 和SQL等攻击方式一样&#xff0c;文件包含漏洞也是一种注入型漏洞&#xff0c;其本质就是输入一段用户能够控制的脚本或者代码&#xff0c;并让服务端执行。 什么叫包含呢&#xff1f;以PHP为例&#xff0c;我们常常把可重复使用的函数写入到单个文件中&…

蓝桥杯 2021年模拟赛 扫雷问题

题目&#xff1a; 在一个 n 行 m 列的方格图上有一些位置有地雷&#xff0c;另外一些位置为空。 请为每个空位置标一个整数&#xff0c;表示周围八个相邻的方格中有多少个地雷。 输入描述 输入的第一行包含两个整数 n,m。 第 22行到第n1 行每行包含 m 个整数&#xff0c;相…

写windows服务日志-.net4.5.2-定时修改数据库中某些参数

环境&#xff1a; windows 11 Visual Studio 2015 .net 4.5.2 SQL Server 目的&#xff1a; 定时修改数据库中某些参数的值 定时修改24小时内&#xff0c;SQL数据库中&#xff0c;表JD_Reports 内&#xff0c;如果部门是‘体检科&#xff0c;设置打印类型为 1 可以打印。步骤&a…

madvise MADV_FREE对文件页统计的影响及原理

一、背景 madvise系统调用是一个与性能优化强相关的一个系统调用。madvise系统调用包括使用madvise函数&#xff0c;也包含使用posix_fadvise函数。如我们可以使用posix_fadvise传入POSIX_FADV_DONTNEED来清除文件页的page cache以减少内存压力。 这篇博客里&#xff0c;我们…