系统城装机大师 - 固镇县祥瑞电脑科技销售部宣传站!

当前位置:首页 > 系统教程 > Linux教程 > 详细页面

Linux文件/目录的权限及归属管理使用

时间:2020-02-02来源:系统城作者:电脑系统城

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

1、访问权限

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

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

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

2、归属(所有权)

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

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

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

Linux文件/目录的权限及归属管理精讲

4、chmod设置文件权限

chmod命令的基本语法格式如下:

Linux文件/目录的权限及归属管理精讲

应用举例:


 
  1. [root@centos01 ~]# touch 1.txt <!--创建1.txt文件-->
  2. [root@centos01 ~]# ll
  3. 总用量 8
  4. -rw-r--r-- 1 root root 0 1月 11 22:27 1.txt
  5. -rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
  6. -rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
  7. [root@centos01 ~]# chmod u+x ./1.txt <!--属主用户添加执行权限-->
  8. [root@centos01 ~]# ll
  9. 总用量 8
  10. -rwxr--r-- 1 root root 0 1月 11 22:27 1.txt
  11. -rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
  12. -rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
  13. [root@centos01 ~]# chmod u-x,g+x,o+w 1.txt
  14. <!--属主用户取消执行权限,组添加执行权限,其他用户添加写入权限-->
  15. [root@centos01 ~]# ll
  16. 总用量 8
  17. -rw-r-xrw- 1 root root 0 1月 11 22:27 1.txt
  18. -rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
  19. -rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
  20. [root@centos01 ~]# chmod 755 1.txt <!--添加755权限(rwxr-xr-x)-->
  21. [root@centos01 ~]# ll
  22. 总用量 8
  23. -rwxr-xr-x 1 root root 0 1月 17 02:36 1.txt
  24. -rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
  25. -rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg

5、chown设置文件的归属

chown命令的基本语法格式如下:

Linux文件/目录的权限及归属管理精讲

应用举例:


 
  1. [root@centos01 ~]# chown bob 1.txt <!--1.txt设置属主-->
  2. [root@centos01 ~]# ll
  3. 总用量 8
  4. -rwxr-xr-x 1 bob root 0 1月 17 02:36 1.txt
  5. -rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
  6. -rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
  7. [root@centos01 ~]# chown :benet 1.txt <!--1.txt设置属组-->
  8. [root@centos01 ~]# ll
  9. 总用量 8
  10. -rwxr-xr-x 1 bob benet 0 1月 17 02:36 1.txt
  11. -rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
  12. -rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
  13. [root@centos01 ~]# chown bob:benet 1.txt <!--1.txt设置属主和属组-->
  14. [root@centos01 ~]# ll
  15. 总用量 8
  16. -rwxr-xr-x 1 bob benet 0 1月 17 02:36 1.txt
  17. -rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
  18. -rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
  19. <!---->

二、目录的权限和归属

1、访问权限

Linux文件/目录的权限及归属管理精讲

2、归属(所有权)

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

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

3、chmod设置目录权限

chmod命令设置目录权限的基本格式如下:

Linux文件/目录的权限及归属管理精讲

应用举例:


 
  1. [root@centos01 ~]# chmod -R 755 benet/
  2. <!--循环设置benet目录下的文件或者目录权限为755-->
  3. [root@centos01 ~]# ll
  4. 总用量 8
  5. -rw-r-xrw- 1 root root 0 1月 11 22:27 1.txt
  6. -rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
  7. drwxr-xr-x 3 root root 18 1月 11 22:39 benet
  8. -rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg

4、chown设置目录的归属

chown命令设置目录归属的基本格式如下:

Linux文件/目录的权限及归属管理精讲

应用举例:


 
  1. [root@centos01 ~]# chown -R bob:benet benet/
  2. <!--循环设置benet目录中所属用户为bob,所属组为benet-->
  3. [root@centos01 ~]# ll
  4. 总用量 8
  5. -rw-r-xrw- 1 root root 0 1月 11 22:27 1.txt
  6. -rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
  7. drwxr-xr-x 3 bob benet 18 1月 11 22:39 benet
  8. -rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg

三、权限掩码umask

1、umask的作用

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

2、设置umask


 
  1. umask 022

3、查看umask


 
  1. umask

4、应用举例:


 
  1. [root@centos01 ~]# umask <!--查看umask-->
  2. 0022
  3. [root@centos01 ~]# umask 000 <!--设置umask为000-->
  4. [root@centos01 ~]# umask <!--验证是否设置成功-->
  5. 0000
  6. [root@centos01 ~]# touch 2.txt <!--创建新文件-->
  7. [root@centos01 ~]# ll
  8. 总用量 8
  9. -rwxr-xr-x 1 bob benet 0 1月 17 03:48 1.txt
  10. -rw-rw-rw- 1 root root 0 1月 17 03:48 2.txt <!--查看权限-->
  11. -rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
  12. -rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
  13. [root@centos01 ~]# umask 022 <!--设置umask为022-->
  14. [root@centos01 ~]# umask <!--查看umask-->
  15. 0022
  16. [root@centos01 ~]# touch 3.txt <!--再次创建新文件-->
  17. [root@centos01 ~]# ll
  18. 总用量 8
  19. -rwxr-xr-x 1 bob benet 0 1月 17 03:48 1.txt
  20. -rw-rw-rw- 1 root root 0 1月 17 03:48 2.txt
  21. -rw-r--r-- 1 root root 0 1月 17 03:49 3.txt <!--查看权限,明显不一样-->
  22. -rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
  23. -rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

本文标题: Linux文件/目录的权限及归属管理使用
分享到:

相关信息

  • linux定时关机设置教程

    当linux在运作时不能直接关闭电源容易将档案系统损毁,因此需要用shutdown以安全的方式关闭,那么这个操作该怎么实现呢?下面就为大家带来了详细教程。...

    2022-11-07

  • linux强制删除文件教程

    由于linux系统和我们常用的windows系统是不一样的,所以如果是初学者,可能会不知道linux怎么强制删除文件,其实我们只要打开终端,使用命令就可以删除了。...

    2022-11-03

系统教程栏目

栏目热门教程

人气教程排行

站长推荐

热门系统下载