资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Linux如何用命令管理文件和目录的权限-创新互联

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

十载的汝城网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。营销型网站的优势是能够根据用户设备显示端的尺寸不同,自动调整汝城建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“汝城网站设计”,“汝城网站推广”以来,每个客户项目都认真落实执行。

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

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

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

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网页名称:Linux如何用命令管理文件和目录的权限-创新互联
分享链接:http://cdkjz.cn/article/dsggoj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220