# ls -l /etc/ 总用量 1088 -rw-r--r--. 1 root root 16 5月 22 01:29 time -rw-r--r--. 1 root root 1518 6月 7 2013 aliases -rw-r--r--. 1 root root 12288 5月 22 01:38 aliases.db "."表示该文件受SELinux控制(SELinux防火墙未彻底关闭时显示)
[root@3 ~]# mkdir test [root@3 ~]# touch ./test/test3 [root@3 ~]# ls -ld test drwxr-xr-x 2 root root 19 6月 6 21:22 test [root@3 ~]# ls -l test 总用量 0 -rw-r--r-- 1 root root 0 6月 6 21:22 test3 [root@3 ~]# chmod 750 test 更改test的权限为750 [root@3 ~]# ls -ld test drwxr-x--- 2 root root 19 6月 6 21:22 test [root@3 ~]# ls -l test/test3 查看test3的权限,未发生改变 -rw-r--r-- 1 root root 0 6月 6 21:22 test/test3 [root@3 ~]# chmod 755 test/test3 更改test3 的权限为755 [root@3 ~]# ls -l test/test3 -rwxr-xr-x 1 root root 0 6月 6 21:22 test/test3 [root@3 ~]# chmod -R 700 test 级联更改test、test3的权限为700 [root@3 ~]# ls -ld test drwx------ 2 root root 19 6月 6 21:22 test [root@3 ~]# ls -l !$ ls -l test 总用量 0 -rwx------ 1 root root 0 6月 6 21:22 test3 !!! test和test3的权限均改成700
eg2:bash
[root@3 ~]# ls -ld test drwx------ 2 root root 19 6月 6 21:22 test [root@3 ~]# ls -l test 总用量 0 -rwx------ 1 root root 0 6月 6 21:22 test2 [root@3 ~]# chmod u=rwx,g=rx,o=rw test 更改test的全部者权限u=rwx,所属组权限g=rx,其余非群组权限o=rw [root@3 ~]# ls -ld test drwxr-xrw- 2 root root 19 6月 6 21:22 test [root@3 ~]# chmod a+x test/test2 更改test2全部权限(包含u,g,o)增长x权限(此处a=all) [root@3 ~]# ls -l test 总用量 0 -rwx--x--x 1 root root 0 6月 6 21:22 test2
[root@3 tmp]# ls -l 总用量 0 drwxr-xr-x 2 root root 22 6月 7 07:23 3 drwx------ 3 root root 17 6月 7 07:16 systemd-private-bd8a94da330a4bc1984e8c95d8651460-vmtoolsd.service-ewuptl [root@3 tmp]# ls -l 3 总用量 0 -rw-r--r-- 1 root root 0 6月 7 07:21 2.txt [root@3 tmp]# chown 3 3/2.txt 更改全部者(user) [root@3 tmp]# ls -l 3 总用量 0 -rw-r--r-- 1 adai root 0 6月 7 07:21 2.txt [root@3 tmp]# chown :user1 3/2.txt 更改所属组(group) [root@3 tmp]# ls -l 3 总用量 0 -rw-r--r-- 1 2 user1 0 6月 7 07:21 2.txt [root@3 tmp]# chown root:root 3/2.txt 同时更改全部者(user)和所属组(group),该命令还能够写成‘chown root.root 3/2.txt’ [root@3 tmp]# ls -l 3 总用量 0 -rw-r--r-- 1 root root 0 6月 7 07:21 2.txt
语法: chgrp [-R] [组名] filename (-R表示级联更改,只针对目录文件)spa
eg1: 更改文件的所属组code
[root@3 ~]# groupadd testgroup 添加组testgroup [root@3 ~]# touch test1 建立文件test1 [root@3 ~]# ls -l test1 -rw-r--r-- 1 root root 0 6月 7 10:39 test1 [root@3 ~]# chgrp testgroup test1 更改文件test1的所属组为testgroup [root@3 ~]# ls -l test1 -rw-r--r-- 1 root testgroup 0 6月 7 10:39 test1
eg2: 更改目录的所属组同步
[root@3 ~]# ls -l dirb/ 总用量 0 drwxr-xr-x 2 root root 6 6月 7 10:51 2 drwxr-xr-x 2 root root 6 6月 7 10:50 dirc [root@3 ~]# ls -ld !$ ls -ld dirb/ drwxr-xr-x 4 root root 30 6月 7 10:51 dirb/ [root@3 ~]# chgrp testgroup dirb/ 更改目录dirb的所属组为testgroup [root@3 ~]# ls -ld !$ ls -ld dirb/ drwxr-xr-x 4 root testgroup 30 6月 7 10:51 dirb/ [root@3 ~]# ls -l !$ ls -l dirb/ 总用量 0 drwxr-xr-x 2 root root 6 6月 7 10:51 2 drwxr-xr-x 2 root root 6 6月 7 10:50 dirc [root@3 ~]# chgrp -R testgroup dirb/ 级联更改目录的所属组(目录下内容的所属组同时跟着改变) [root@3 ~]# ls -l !$ ls -l dirb/ 总用量 0 drwxr-xr-x 2 root testgroup 6 6月 7 10:51 2 drwxr-xr-x 2 root testgroup 6 6月 7 10:50 dirc
注: 由于chown命令能够替代chgrp命令,因此chgrp命令使用的并很少。it
>当咱们登陆系统以后建立一个文件老是有一个默认权限的,那么这个权限是怎么来的呢?这就是umask干的事情。umask设置了用户建立文件的默认权限,它与chmod的效果恰好相反,umask设置的是权限"补码",而chmod设置的是文件权限码。umask的默认值能够更改,可是只有在$[HOME]/.bashrc下增长umask值才能够永久定义本身的umask值,不然只是临时更改。
语法: umask xxx (此处xxx表明三个数字)test
[root@3 ~]# umask 查看umask值 0022 即:umask的预设是0022 [root@3 ~]# umask 020 预设umask值为020 [root@3 ~]# umask 0020 [root@3 ~]# umask 022 [root@3 ~]# umask 0022
注: 默认状态下,文件umask+chmod=666;目录umask+chmod=777(限于权限位加减法)。登录
>只有超级权限的用户才具备使用该命令的权限,这项指令可改变存放在ext二、ext三、ext四、xfs、ubifs、reiserfs、jfs等文件系统上的文件或目录属性。file