一、作用

  1. chmod命令是控制用户对文件的权限的命令

二、选项

  • -f 若该文件权限无法被更改也不要显示错误讯息
  • -R 处理指定目录以及其子目录下的所有文件

    三、实例

    [root@xxxx:/data/txt ]# ll
    total 0
    -rw-r--r-- 1 root root 0 Jun  9 11:37 bo.txt1
    [root@xxxx:/data/txt ]# chmod u=rwx,g=rwx,o=rw bo.txt1 
    [root@xxxx:/data/txt ]# ll
    total 0
    -rwxrwxrw- 1 root root 0 Jun  9 11:37 bo.txt1
    
    [root@localhost dir]# ll 1.txt 
    -rw-r--r-- 1 root root 0 6月  17 13:43 1.txt
    [root@localhost dir]# chmod o+rw 1.txt 
    [root@localhost dir]# ll 1.txt 
    -rw-r--rw- 1 root root 0 6月  17 13:43 1.txt
    
    [root@localhost dir]# chmod -f  1233 1.txt 
    [root@localhost dir]# ll 1.txt 
    --w--wx-wt 1 root root 0 6月  17 13:43 1.txt
    
    ``` [root@xxxx:/data/txt ]# ll bo.txt1 -rwxrwxrw- 1 root root 0 Jun 9 11:37 bo.txt1 [root@xxxx:/data/txt ]# chmod 644 bo.txt1 [root@xxxx:/data/txt ]# ll bo.txt1 -rw-r—r— 1 root root 0 Jun 9 11:37 bo.txt1

```

  • u 表示该文件的拥有者,g 表示与该文件的拥有者属于同一个group,o 表示其他以外的人,a 表示这三者皆是。
    • 表示增加权限、- 表示取消权限、= 表示唯一设定权限。
  • r 表示可读取,w 表示可写入,x 表示可执行,X 表示只有当该文件是个子目录或者该文件已经被设定过为可执行。

    r —> 4 r+w+x =7 r+x=5
    w —> 2 r+w =6
    x —> 1