网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Linux如何用命令管理文件和目录的权限

Linux如何用命令管理文件和目录的权限?针对这个问题,今天小编总结这篇有关linux文件和目录权限的文章,可供感兴趣的小伙伴们参考借鉴,希望对大家有所帮助。

创新互联建站坚信:善待客户,将会成为终身客户。我们能坚持多年,是因为我们一直可值得信赖。我们从不忽悠初访客户,我们用心做好本职工作,不忘初心,方得始终。10余年网站建设经验创新互联建站是成都老牌网站营销服务商,为您提供成都网站设计、成都网站制作、网站设计、H5网站设计、网站制作、品牌网站制作、小程序制作服务,给众多知名企业提供过好品质的建站服务。

一、文件的权限和归属概述

1、访问权限

  • 读取r:允许查看文件内容、显示目录列表;

  • 写入w:允许修改文件内容,允许在目录中新建、移动、删除文件或子目录;

  • 可执行x:允许运行程序、切换目录

2、归属(所有权)

  • 属主:拥有该文件或目录的用户账号;

  • 属组:拥有该文件或目录的组账号;

3、查看文件的权限和归属

Linux如何用命令管理文件和目录的权限

4、chmod设置文件权限

chmod命令的基本语法格式如下:
Linux如何用命令管理文件和目录的权限

应用举例:

[root@centos01 ~]# touch 1.txt     
[root@centos01 ~]# ll 
总用量 8
-rw-r--r--  1 root root    0 1月  11 22:27 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chmod u+x ./1.txt  
[root@centos01 ~]# ll
总用量 8
-rwxr--r--  1 root root    0 1月  11 22:27 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chmod u-x,g+x,o+w 1.txt   

[root@centos01 ~]# ll
总用量 8
-rw-r-xrw-  1 root root    0 1月  11 22:27 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chmod 755 1.txt  
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x  1 root root    0 1月  17 02:36 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg

5、chown设置文件的归属

chown命令的基本语法格式如下:
Linux如何用命令管理文件和目录的权限

应用举例:

[root@centos01 ~]# chown bob 1.txt  
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x  1 bob  root    0 1月  17 02:36 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chown :benet 1.txt  
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x  1 bob  benet    0 1月  17 02:36 1.txt
-rw-------. 1 root root  1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root  1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chown bob:benet 1.txt  
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x  1 bob  benet    0 1月  17 02:36 1.txt
-rw-------. 1 root root  1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root  1603 10月 23 23:36 initial-setup-ks.cfg

二、目录的权限和归属

1、访问权限

Linux如何用命令管理文件和目录的权限

2、归属(所有权)

  • 属主:拥有该目录的用户账号;

  • 属组:拥有该目录的组账号;

3、chmod设置目录权限

chmod命令设置目录权限的基本格式如下:
Linux如何用命令管理文件和目录的权限

应用举例:

[root@centos01 ~]# chmod -R 755 benet/   
          
[root@centos01 ~]# ll
总用量 8
-rw-r-xrw-  1 root root    0 1月  11 22:27 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
drwxr-xr-x  3 root root   18 1月  11 22:39 benet
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg

4、chown设置目录的归属

chown命令设置目录归属的基本格式如下:
Linux如何用命令管理文件和目录的权限

应用举例:

[root@centos01 ~]# chown -R bob:benet benet/   
   
[root@centos01 ~]# ll
总用量 8
-rw-r-xrw-  1 root root     0 1月  11 22:27 1.txt
-rw-------. 1 root root  1572 10月 23 22:37 anaconda-ks.cfg
drwxr-xr-x  3 bob  benet   18 1月  11 22:39 benet
-rw-r--r--. 1 root root  1603 10月 23 23:36 initial-setup-ks.cfg

三、权限掩码umask

1、umask的作用

控制新建的文件或目录的权限,默认权限去除umask的权限就是新建的文件或者目录的权限。

2、设置umask

umask 022

3、查看umask

umask

4、应用举例:

[root@centos01 ~]# umask  
0022
[root@centos01 ~]# umask 000  
[root@centos01 ~]# umask   
0000
[root@centos01 ~]# touch 2.txt   
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x  1 bob  benet    0 1月  17 03:48 1.txt
-rw-rw-rw-  1 root root     0 1月  17 03:48 2.txt    
-rw-------. 1 root root  1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root  1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# umask 022       
[root@centos01 ~]# umask           
0022
[root@centos01 ~]# touch 3.txt        
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x  1 bob  benet    0 1月  17 03:48 1.txt
-rw-rw-rw-  1 root root     0 1月  17 03:48 2.txt
-rw-r--r--  1 root root     0 1月  17 03:49 3.txt 
-rw-------. 1 root root  1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root  1603 10月 23 23:36 initial-setup-ks.cfg

看完这篇文章,你们学会管理文件和目录的权限的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读。


当前标题:Linux如何用命令管理文件和目录的权限
网页URL:http://bjjierui.cn/article/jdcepc.html

其他资讯