linux文件权限-chmod、chown、chgrp

1、文件权限介绍

1.1、文件权限显示解析

如:
-rw-r--r-- 1 root root 11 Apr 19 21:48 pass.txt
-rw 所属主【user】
r-- 所属组【group】
r-- 其它用户权限【other】

1.2、权限rwx解析

字母   含义       二进制   八进制
r--    读取权限   100      4
-w-    写入权限   010      2
--x    执行权限   001      1
---    没有权限   000      0

2、chmod

2.1、ugo方式

2.1.1、给所有人添加权限

chmod a=rwx pass.txt 
[root@linux ~]# ll pass.txt 
-rwxrwxrwx 1 root root 11 Apr 19 21:48 pass.txt

2.1.2、给所有人删除权限

chmod a=-rwx pass.txt 
[root@linux ~]# ll pass.txt 
---------- 1 root root 11 Apr 19 21:48 pass.txt

2.1.3、属主读写执行,属组读写,其他人无权限

chmod u=rwx,g=rw,o=- pass.txt 
[root@linux ~]# ll pass.txt 
-rwxrw---- 1 root root 11 Apr 19 21:48 pass.txt

2.1.4、属主属组读写执行,其他人读权限

chmod ug=rwx,o=r pass.txt 
[root@linux ~]# ll pass.txt 
-rwxrwxr-- 1 root root 11 Apr 19 21:48 pass.txt

2.2、八进制方式

2.2.1、给所有人添加权限

chmod 777 pass.txt 
[root@linux ~]# ll pass.txt 
-rwxrwxrwx 1 root root 11 Apr 19 21:48 pass.txt

2.2.2、给所有人删除权限

chmod 000 pass.txt 
[root@linux ~]# ll pass.txt 
---------- 1 root root 11 Apr 19 21:48 pass.txt

2.2.3、属主读写执行,属组读写,其他人无权限

chmod 760 pass.txt 
[root@linux ~]# ll pass.txt 
-rwxrw---- 1 root root 11 Apr 19 21:48 pass.txt

2.2.4、属主属组读写执行,其他人读权限

chmod 664 pass.txt 
[root@linux ~]# ll pass.txt 
-rw-rw-r-- 1 root root 11 Apr 19 21:48 pass.txt

2.3、目录授权-示例

2.3.1、设置目录所属主读写执行权限,其它没有权限

chmod 700  -R Python-3.10.10
[root@linux ~]# ll
drwx------ 19 cyc  ops      4096 Feb 19 21:26 Python-3.10.10

# -R 表示递归的意思

3、chown

3.1、命令介绍

chown (change owner),chown能变更文件的属主和属组

3.2、示例

3.2.1、创建测试目录

[root@linux ~]# mkdir /mnt/test
[root@linux ~]# ll /mnt/
total 0
drwxr-xr-x 2 root root 6 Apr 20 11:38 test

3.2.2、修改所属的主

[root@linux ~]# chown bin /mnt/test
[root@linux ~]# ll /mnt
drwxr-xr-x 2 bin root 6 Apr 20 11:38 test

3.2.3、修改所属组

[root@linux ~]# chown .adm /mnt/test
[root@linux ~]# ll /mnt/
drwxr-xr-x 2 bin adm 6 Apr 20 11:38 test

3.2.4、同时修改所属主、所属组为root,并且递归

[root@linux ~]# chown root.root -R /mnt/test
[root@linux ~]# ll /mnt
drwxr-xr-x 2 root root 6 Apr 20 11:38 test

4、chgrp

4.1、命令介绍

chgrp (change group),chgrp 仅能变更文件的属组;

4.2、示例

4.2.1、创建目录,修改所属组

[root@linux ~]# mkdir /mnt/test
[root@linux ~]# ll /mnt/
drwxr-xr-x 2 root root 6 Apr 20 11:44 test

[root@linux ~]# chgrp adm /mnt/test
[root@linux ~]# ll /mnt
drwxr-xr-x 2 root adm 6 Apr 20 11:44 test

 

posted @   小粉优化大师  阅读(53)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示